form validation
| From: | Chris Stinemetz | Date: | Fri, 12 Aug 2011 15:42:02 +0000 |
| Subject: | form validation | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-314513@lists.php.net to get a copy of this message | ||
I have a select menu created by a foreach loop. I am trying to
validate that there was a selection made before it is submitted to the
database. But I am not doing something correctly.
<select name="market" class="ajax"
onchange="javascript:get(this.parentNode);">
<option value="">Choose...</option>
<?php
foreach($market_prefix as $key => $value)
{
$selected = '';
if($value == $market)
{
$selected = 'selected';
}
echo '<option value="', htmlspecialchars($value), '" ', $selected,
'>', htmlspecialchars($market_name[$key]), '</option>';
}
?>
</select>
I am using the folling on the posted page.
if (! array_key_exists($_POST['market'], $market_name))
{
echo "You did not select a market.";
}
Thank you,
Chris