Opally
07-30-2008, 04:26 PM
I'm building a PHP form which uses a drop-down menu. I want to validate that an option has been selected before submitting the form. My validation is always failing (I'm sure this has a simple fast solution!)
$roundtables = trim($_POST['roundtables']);
if ($roundtables = 'Please Select') {
$error['roundtables'] = 'Please select your roundtable';
}
$roundtableslist = array(0 => 'Please Select',
1 => 'Art',
2 => 'Music',
3 => 'Special Education'
);
<label for="roundtables">Roundtables:</label> <?php if
(isset($error['roundtables'])) { ?>
<span class="warning"><?php echo $error['roundtables']; ?></span>
<?php } ?>
<br />
<select name="roundtables" id="roundtables">
<?php foreach($roundtableslist as $id => $value) { ?>
<option value="<?php echo $value; ?> "
<?php if (isset($error) && $roundtables == $value ) { ?>
selected="selected" <?php } ?>><?php echo $value; ?></option>
<?php } ?>
</select>
"if ($roundtables = 'Please Select')" is always evaluating true, it seems.
Muchas gracias in advance for your help!!
--Diana
$roundtables = trim($_POST['roundtables']);
if ($roundtables = 'Please Select') {
$error['roundtables'] = 'Please select your roundtable';
}
$roundtableslist = array(0 => 'Please Select',
1 => 'Art',
2 => 'Music',
3 => 'Special Education'
);
<label for="roundtables">Roundtables:</label> <?php if
(isset($error['roundtables'])) { ?>
<span class="warning"><?php echo $error['roundtables']; ?></span>
<?php } ?>
<br />
<select name="roundtables" id="roundtables">
<?php foreach($roundtableslist as $id => $value) { ?>
<option value="<?php echo $value; ?> "
<?php if (isset($error) && $roundtables == $value ) { ?>
selected="selected" <?php } ?>><?php echo $value; ?></option>
<?php } ?>
</select>
"if ($roundtables = 'Please Select')" is always evaluating true, it seems.
Muchas gracias in advance for your help!!
--Diana