How to validate an array in a PHP form?
Posted
by SlAcKeR
on Stack Overflow
See other posts from Stack Overflow
or by SlAcKeR
Published on 2010-03-18T18:38:45Z
Indexed on
2010/03/18
18:41 UTC
Read the original article
Hit count: 210
php
I'm fairly new to php and was wondering how do I validate the array for the states and where do I place the php code at? I already did the address part but I'm stuck at the states part.
Here is the validation code.
if (isset($_POST['contact_info_submitted'])) { // Handle the form.
$address = mysqli_real_escape_string(htmlentities($_POST['address']));
}
Here is the form code.
<li><label for="address-1">Address 1: </label><input type="text" name="address-1" id="address-1" size="25" class="input-size" value="<?php if (isset($_POST['address'])) echo $_POST['address']; ?>" /></li>
<li><label for="state-province">State/Province: </label>
<?php
echo '<select name="state-province" id="state-province">' . "\n";
foreach($state_options as $option) {
if ($option == $state) {
echo '<option value="' . $option . '" selected="selected">' . $option . '</option>' . "\n";
} else {
echo '<option value="'. $option . '">' . $option . '</option>'."\n";
}
}
echo '</select>';
?>
</li>
© Stack Overflow or respective owner