Forum Moderators: coopster
I can't get this to work. The problem is with validating the user's selection from the drop down menu, in this case the Department Chair. I've included all the code from the form and just the department chair validation from the action form. What am I doing wrong?
Here is the form
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Availability Statement</title>
</script>
<link rel="stylesheet" type="text/css" href="available.css">
</head>
<body>
<form action="availableHandle.php" method="POST">
<img src="images/cpcLogo.jpg" alt="Cogswell Polytechnical College" border="1" longdesc="http://www.example.edu" />
<h1>Cogswell Polytechnical College</h1>
<h2>Availability Statement - Adjunct Unit Members</h2>
<?php
//get todays date
$today = date("F j, Y");
echo "Today's date: $today";
?>
<br /><br />
<fieldset>
<br />
<legend>Faculty Information</legend>
<label for="fname">First name: </label><img src="images/spacer.gif" height="1" width="8" /></td>
<input name="fname" type="text" value="" size="20" maxlength="25" /><br /><br />
<label for="lname">Last name: </label><img src="images/spacer.gif" height="1" width="10" /></td>
<input name="lname" type="text" value="" size="20" maxlength="25" /><br /><br />
<label for="extension">Extension: </label><img src="images/spacer.gif" height="1" width="14" /></td>
<input name="extension" type="text" size="20" maxlength="25" /><br /><br />
<label for="chair">Select your Department Chair: </label>
<?php
$chair = array (1 => '- - - select - - -', 'Nancy Fetterman', 'Wanda Keesling', 'Lawrence Garner', 'Robert Lopez', 'Susan Harby');
echo '<select name="chair">';
foreach ($chair as $key => $value) {
echo "<option value=\"$key\">$value</option>\n";
}
echo '</select>';
?>
<br /><br />
<label for="division">Select your Division: </label>
<?php
$division = array (1 => '- - - select - - -', 'NAS', 'VAPA', 'DMIS', 'BAL', 'HASS');
sort($division);
echo '<select name="division">';
foreach ($division as $key => $value) {
echo "<option value=\"$key\">$value</option>\n";
}
echo '</select>';
?>
<br /><br />
<label for "department">Select your Department: </label>
<?php
$department = array (1 => '- - - select - - -', 'Math', 'English', 'Art History', 'English', 'History');
sort($department);
echo '<select name="department">';
foreach ($department as $key => $value) {
echo "<option value=\"$key\">$value</option>\n";
}
echo '</select>';
?>
<br /><br />
</fieldset>
<br />
<fieldset>
<br />
<legend>Select All That Apply</legend>
<input name="interest" type="checkbox" value="isinterest" />I am interested in an adjunct assignment starting
<?php
$years = range (2006, 2015);
$semester = array (1 => '- - - select - - -', 'Fall', 'Winter Session', 'Spring', 'Summer Session');
echo '<select name="semester">';
foreach ($semester as $value) {
echo "<option value=\"$value\">$value</option>\n";
}
echo '</select>';
?>
<img src="images/spacer.gif" width="5" height="1" />
<?php
echo '<select name="years">';
foreach ($years as $key => $value) {
echo "<option value=\"$key\">$value</option>\n";
}
echo '</select>';
?>
<br /><br />
<input name="interest" type="checkbox" value="nointerest" />I will not be available for an adjunct assignment until
<?php
$years1 = range (2006, 2015);
$semester1 = array (1 => '- - - select - - -', 'Fall', 'Winter Session', 'Spring', 'Summer Session');
echo '<select name="semester1">';
foreach ($semester1 as $value) {
echo "<option value=\"$value\">$value</option>\n";
}
echo '</select>';
?>
<img src="images/spacer.gif" width="5 height="1" />
<?php
echo '<select name="years1">';
foreach ($years1 as $key => $value) {
echo "<option value=\"$key\">$value</option>\n";
}
echo '</select>';
?>
<br /><br />
</fieldset>
<br />
<fieldset>
<br />
<legend>Availability</legend>
If you have specific time, day, or course restrictions or special considerations, please note them here:<br />
<textarea name="details" cols="85" rows="3"></textarea>
<br /><br />
<input name="submit" type="submit" value="Submit Your Availability" /><input name="reset" type="reset" value="Clear and Try Again" />
</fieldset>
</form>
</body>
</html>
Here is the validation
if (trim($_REQUEST['chair'] == '- - - select - - -')){
echo "<p>Required field: Select your Department Chair</p>";
} else {
$chair = (trim($_REQUEST['chair']));
}
[edited by: coopster at 3:33 pm (utc) on Nov. 16, 2006]
[edit reason] generalized domain [/edit]
Change your drop down code to the following:
echo "<option>$value</option>\n";
At the moment the value of $_POST['department'] will be a number, ie the key of the array. I`m guessing you want the department name, in which case all is needed is the value unless you are doing a check on the number when processing. Hope that makes sense.
dc