terrid25 Posted December 9, 2010 Share Posted December 9, 2010 Hi I have a form that is to input data from input fields to a table. The form is as follows: $query = $DB->query("SELECT country_code, country_id, IF(country_code = '".$country_code."', '', '') AS sel FROM exp_sme_countries WHERE site_id='".$this->settings['site_id']."' ORDER BY country_name ASC"); foreach ($query->result as $row) { $options .= '<label>' . 'Phrase for ' . $this->settings['countries'][$row['country_code']] . '</label>' . '<br />'; $options .= '<input style="width: 100%; height: 5%;" id="country_data" type="text" name="country_id[]" />' . '<br /><br />'; $options .= '<input type="hidden" name="country_data[' . $row['country_id'] . ']" value="'.$row['country_id'].'" />'; } This outputs: <input style="width: 100%; height: 5%;" id="country_data" type="text" name="country_id[]" /> <input type="hidden" name="country_data[68]" value="68" /> <input style="width: 100%; height: 5%;" id="country_data" type="text" name="country_id[]" /> <input type="hidden" name="country_data[28]" value="28" /> What I need to do, is get the values from the input fields and then match them with the correct hidden field value So if in the first input field, I typed in 'Test data' and the second input, i typed 'This is great' On the POST, I need to find the the value ('Test data') and also the value from the hidden field. So something like: The text you entered is: Test data with hidden value of 68 The text you entered is: This is great with hidden value of 28 I'd rather not use $_GET as this is a form that inserts data into a database. Could someone point my in the right direction or provide an example? Quote Link to comment https://forums.phpfreaks.com/topic/221119-getting-matching-post-values-from-input-fields/ Share on other sites More sharing options...
AbraCadaver Posted December 9, 2010 Share Posted December 9, 2010 Don't give the hidden input an index so it should be the same as the text input: <input style="width: 100%; height: 5%;" id="country_data" type="text" name="country_id[]" /> <input type="hidden" name="country_data[]" value="68" /> <input style="width: 100%; height: 5%;" id="country_data" type="text" name="country_id[]" /> <input type="hidden" name="country_data[]" value="28" /> $text = $_POST['country_id']; $data = $_POST['country_data']; foreach($text as $key => $value) { echo "The text you entered is: $value with hidden value of " . $data[$key]; } Quote Link to comment https://forums.phpfreaks.com/topic/221119-getting-matching-post-values-from-input-fields/#findComment-1144973 Share on other sites More sharing options...
PFMaBiSmAd Posted December 9, 2010 Share Posted December 9, 2010 I don't see the need for the hidden field at all, just use the value as the country_id[...] index - <input style="width: 100%; height: 5%;" id="country_data" type="text" name="country_id[68]" /> <input style="width: 100%; height: 5%;" id="country_data" type="text" name="country_id[28]" /> .... Quote Link to comment https://forums.phpfreaks.com/topic/221119-getting-matching-post-values-from-input-fields/#findComment-1144976 Share on other sites More sharing options...
terrid25 Posted December 10, 2010 Author Share Posted December 10, 2010 Both worked great! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/221119-getting-matching-post-values-from-input-fields/#findComment-1145272 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.