hi guys…
Im currently working on a form which will be validated through php due not to catch
those who dont got javascript also
I made it in php5 with try and catch and it worked perfectly until i realized after uploading
that my server is not php5 yet. Fun ey…
So now im working on a list in php4 but it doenst work like i want it really.
I want my select list to have a default value such as “Select…” and
if user have this to give an error message…
The code i got is this one
$flavors = array(‘Vanilla’,‘Chocolate’,‘Rhinoceros’);
if ((empty ($_POST['flavor']))) {
$msg= "Choose a valid flavor.";
}
foreach ($flavors as $flavor) {
if (isset($_POST[‘flavor’]) && ($_POST[‘flavor’] == $flavor)) {
$defaults[‘flavor’][$flavor] = “selected=‘selected’”;
} else {
$defaults[‘flavor’][$flavor] = ‘’;
}
}
// Here goes the select list in the form
<select name=‘flavor’>
<?php foreach ($flavors as $flavor) {
echo “<option {$defaults[‘flavor’][$flavor]}>$flavor</option>”;
} ?>
</select>
<br>
<?php
echo $msg;
?>