...

View Full Version : Validating drop-down menu



Opally
07-30-2008, 05: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

Apothem
07-30-2008, 06:14 PM
$roundtables = 'Please Select'
Should be:
$roundtables == 'Please Select'

Opally
07-30-2008, 06:41 PM
heh, I kept plugging away after I posted that, and I just figured it out too. You're exactly right, it's the old double-equals-sign comparator trick.

thanks a bunch for posting!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum