Help with Required text box fields
Posted: Mon Mar 30, 2009 9:58 am
Hi, im wondering a good way to go about this. I have just 4 simple text boxes that would like to make required, and if a user does not enter anything and clicks submit i want an error or something to happen to alert them, maybe have a red asterik appear next the text box?.
Thanks!
Code for form:
Mailer Code:
Thanks!
Code for form:
Code: Select all
<?php
<head>
<style type="text/css">
.style1 {
font-size: large;
}
</style>
</head>
<strong><span class="style1">Application Request Form</span></strong>
<br>
<br>
<form method="POST" action="mailer.php">
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td><strong>Staff Name</strong>:</td>
<td><input type="text" name="name" size="19"></td>
</tr>
<tr>
<td><strong>Title</strong>:</td>
<td><input type="text" name="title" size="19"></td>
</tr>
<tr>
<td><strong>Supervisor Name</strong>:</td>
<td><input type="text" name="supervisor" size="19"></td>
</tr>
<tr>
<td><strong>Location</strong>:</td>
<td><input type="text" name="location" size="19"></td>
</tr>
<tr>
<td valign="top"><strong>Please Select The Applications Needed</strong>:<br>
(<em>Please include the lvl of access in the<br>
message below, IE: READ ONLY</em>)</td>
<td>
<input type="checkbox" name="check[]" value="ADP"> ADP<br>
<input type="checkbox" name="check[]" value="AIRS"> AIRS<br>
<input type="checkbox" name="check[]" value="Awards"> Awards<br>
<input type="checkbox" name="check[]" value="DD-Database"> DD Database<br>
</td>
<td>
<input type="checkbox" name="check[]" value="ecompas"> eCOMPAS<br>
<input type="checkbox" name="check[]" value="FundEZ"> FundEZ<br>
<input type="checkbox" name="check[]" value="HCPlus"> HCPlus<br>
<input type="checkbox" name="check[]" value="HRPC Database"> HRPC Database<br>
</td>
<td>
<input type="checkbox" name="check[]" value="IATS"> IATS<br>
<input type="checkbox" name="check[]" value="IEP Plus"> IEP Plus<br>
<input type="checkbox" name="check[]" value="Nexsus"> Nexsus<br>
<input type="checkbox" name="check[]" value="Yardi"> Yardi<br>
</td>
</tr>
<tr>
<td><strong>Message</strong>:</td>
</tr>
<td><textarea name="message" style="height: 43px; width: 225px"></textarea></td>
</table>
<input type="submit" value="Submit" name="submit">
</form>
?>
Code: Select all
<?php
if(isset($_POST['submit'])) {
//$to = "apinori@susinc.org";
$subject = "Application Request";
$name_field = $_POST['name'];
$title_field = $_POST['title'];
$supervisor_field = $_POST['supervisor'];
$location_field = $_POST['location'];
$message = $_POST['message'];
$to = array();
foreach($_POST['check'] as $key => $value) {
$check_msg .= "Checked: $value\n";
switch($value){
case 'ADP':
$to[$key] = '.org';
break;
case 'AIRS':
$to[$key] = '.org';
break;
case 'Awards':
$to[$key] = '.org';
break;
case 'DD-Database':
$to[$key] = '.org';
break;
case 'eCOMPAS':
$to[$key] = '.org';
break;
case 'FundEZ':
$to[$key] = '.org';
break;
case 'HCPlus':
$to[$key] = '.org';
break;
case 'HRPC Database':
$to[$key] = '.org';
break;
case 'IATS':
$to[$key] = '.org';
break;
case 'IEP Plus':
$to[$key] = '.org';
break;
case 'Nexsus':
$to[$key] = '.org';
break;
case 'Yardi':
$to[$key] = '.org';
break;
default:
$to[$key] = 'Error';
}
}
echo '<br /><b>Thank You:</b><ul>';
foreach($to as $key => $person){
if($person == 'error'){
echo '<li style="color: #900">Error! '.htmlentities($_POST['check'][$key]).' is not a valid Application!</li>';
continue;
}
$body = "Staff Name: $name_field\n Title: $title_field\n Supervisor: $supervisor_field\n Location: $location_field\n Message:\n $message\n Application: {$_POST['check'][$key]}\n";
mail($person, $subject, $body);
echo '<li>Application '.$_POST['check'][$key].': Your Request for a Login was successfully sent, <br>an email with a USERID and password will be sent to the Supervisor.</li>';
}
echo '</ul>';
}
?>