Click to See Complete Forum and Search --> : New to form making


prophit
01-31-2007, 11:15 PM
Well i finally finished my first full form with validation and some other neat goodies. I wanted to know if there was a simpler way to make this work?
Do to the Character restriction i left out the javascript section

<div id="hd">Hardware Replacement</div>
<hr width="100%"><br>

If equipment needs to be replaced you would need to fill out the form below<br>
Also create a Hardware replacement ticket for the device that needs to be replaced<br>
<br>
<br>


<?php

if(isset($_POST["submit"])){

$rfr = htmlentities($_POST['rfr']);
$mk = htmlentities($_POST['make']);
$md = htmlentities($_POST['model']);
$sn = htmlentities($_POST['sn']);
$ma = htmlentities($_POST['mac']);
$ip = htmlentities($_POST['ipaddr']);
$pp = htmlentities($_POST['prop']);
$ct = htmlentities($_POST['contact']);
$sp = htmlentities($_POST['ship']);
$tt = htmlentities($_POST['ticket']);
$cm = htmlentities($_POST['status']);

$error_msg='';
if(trim($_POST["rfr"])=='') {
$error_msg.="Please enter a Reason for replacing!<br>";
}
if(trim($_POST["make"])==''){
$error_msg.="Please select a Make!<br>";
}
if(trim($_POST["model"])=='') {
$error_msg.="Please select a Model!<br>";
}
if(trim($_POST["sn"])=='') {
$error_msg.="Please enter the Serial?<br>";
}
if(trim($_POST["mac"])=='') {
$error_msg.="Please enter the MAC Address?<br>";
} else { if(!ereg("^([0-9a-zA-Z]{2})\:([0-9a-zA-Z]{2})\:([0-9a-zA-Z]{2})\:([0-9a-zA-Z]{2})\:([0-9a-zA-Z]{2})\:([0-9a-zA-Z]{2})$", $_POST["mac"])) $error_msg.="Please enter a valid mac address<br>";
}
if(trim($_POST["ipaddr"])=='') {
$error_msg.="Please enter the IP Address<br>";
}else{
if(!ereg("^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$", $_POST["ipaddr"])) $error_msg.="Please enter a valid IP address<br>";
}
if(trim($_POST["prop"])=='' || strlen(trim($_POST["prop"])) < 5) {
$error_msg.="Please enter the Property Number<br>";
}
if(trim($_POST["contact"])=='') {
$error_msg.="Please enter a contact person<br>";
}
if(trim($_POST["ship"])=='') {
$error_msg.="Please enter the type of shipping<br>";
}
if(trim($_POST["ticket"])=='' || strlen(trim($_POST["ticket"])) > 6 || strlen(trim($_POST["ticket"])) < 6) {
$error_msg.="Make sure the ticket number is 6 digits<br>";
} else {
if(!ereg("[0-9]", $_POST["ticket"])) $error_msg.="Please enter a valid ticket number<br>";
}

if($error_msg==''){

echo '<br><b>Your request has been sent to the Hsia Hardware group</b>.<br>'.
'Please copy the text below and post into your Hardware replacement ticket';

$headers= 'MIME-Version: 1.0'."\r\n";
$headers.= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers.= 'From: hsia@bestwestern.com'."\r\n";

$to = "stacy.welch@bestwestern.com";
$subject = "Hardware Request Property $pp";
$message = "<html><body><table border='0' width= '60%'><tr><td>Reason Requesting Replacement:</td><td>$rfr</td></tr><tr><td>Make/Model Number:</td><td>$mk , $md</td></tr><tr><td>Serial Number:</td><td> $sn</td></tr><tr><td>MAC Address:</td><td>$ma</td></tr><tr><td>IP Address:</td><td>$ip</td></tr><tr><td>Property ID:</td><td>$pp</td></tr><tr><td>Property Contact Name/Title:</td><td>$ct</td></tr><tr><td>Shipping Severity:</td><td>$sp</td></tr><tr><td>Ticket Number :</td><td>$tt</td></tr><tr><td>Comments:</td><td>$cm</td></tr></body></html>";

mail ($to, $subject, $message, $headers);

$form = "
Reason for requesting replacement: $rfr
Make/Model Number: $mk , $md
Serial Number: $sn
MAC Address: $ma
IP Address: $ip
Property ID: $pp
Property ContactName/Title: $ct
Shipping Severity: $sp
Ticket Number: $tt
Comments: $cm
";


echo '<form name="testform">'.
'<textarea name="testsquare" rows="20" cols="56" >';
echo $form;
echo '</textarea>'.
'<br>'.
'<input type="button" onclick="return copy_clip(document.testform.testsquare.value)" value="Copy to Clipboard">'.
'</form>'.
'<form method="post" action="hardware.php">'.
'<input type="submit" value="Hardware Replacement" name="reset">'.
'</form>';
}else{
echo '<font color=red>'.$error_msg.'</font><br>';

echo '<form method="post" action="'. $_SERVER['PHP_SELF'] .'" name="equipment">'.
'<table border="0" id="hardware" width="80%">'.
'<tr>'.
'<td width="30%">Reason for Replacement:</td>'.
'<td><input type="text" name="rfr" size="60" value="'. htmlspecialchars(stripslashes($rfr)).'" ><br></td>'.
'<tr><td width="30%">Make :</td><td>'.
'<select name="make" id="make" onchange="populate()">';
foreach(array('Please Choose A Model', 'Zyxel', 'Nomadix', 'Proxim', 'Ascendance', 'BCEG') as $opt)
{
$selected = ($opt == $mk) ? ' selected' : '';
echo "<option value='$opt'$selected>$opt</option>\n";
}
echo '</SELECT>'.
'</td>'.
'</tr><tr>'.
'<td width="30%">Model :</td><td>'.
'<select name="model" value="'. htmlspecialchars(stripslashes($md)).'">'.
'<option>Please Select A Model</option>'.
'</SELECT>';
?>
<script language="javascript" type="text/javascript">
populate('<?php print $_POST["model"]; ?>');
</script>
<?php echo '</td>'.
'</tr>'.
'<tr><td width="30%">Serial Number:</td><td><input type="text" name="sn" size="20" value="'. htmlspecialchars(stripslashes($sn)).'"></tr></td>'.
'<tr><td width="30%">Mac Address:</td><td><input type="text" name="mac" size="20" value="'. htmlspecialchars(stripslashes($ma)).'"></tr></td>'.
'<tr><td width="30%">IP Address:</td><td><input type="text" name="ipaddr" size="20" value="'. htmlspecialchars(stripslashes($ip)).'"></tr></td>'.
'<tr><td width="30%">Property ID:</td><td><input type="text" name="prop" size="7" value="'. htmlspecialchars(stripslashes($pp)).'"></tr></td>'.
'<tr><td width="30%">Property Contact Name/Title: </td><td><input type="text" name="contact" size="20" value="'. htmlspecialchars(stripslashes($ct)).'"></tr></td>'.
'<tr><td width="30%">Shipping:</td><td>'.
'<select name="ship" id="ship">';
foreach(array('Method of Shipping', 'Ground', 'Next Day Air', 'Next Day Saturday', '2nd Day', '3 day') as $opt2)
{
$selected = ($opt2 == $sp) ? ' selected' : '';
echo "<option value='$opt2'$selected>$opt2</option>\n";
}
echo '</SELECT></tr></td>'.
'<tr><td width="30%">Ticket#:</td><td><input type="text" name="ticket" size="7" value="'. htmlspecialchars(stripslashes($tt)).'"></tr></td>'.
'<tr><td width="30%">Comments:</td><td>'.
'<textarea name="status" rows="4" cols="40">'. htmlspecialchars(stripslashes($cm)).'</textarea></td></tr>'.
'</table><br>'.
'<input type="submit" name="submit" value="Submit Request">'.
'</form>';
}

}else{




echo '<form method="post" action="'. $_SERVER['PHP_SELF'] .'" name="equipment">'.
'<table border="0" id="hardware" width="80%">'.
'<tr>'.
'<td width="30%">Reason for Replacement:</td>'.
'<td><input type="text" name="rfr" size="60" value="'. htmlspecialchars(stripslashes($rfr)).'" ><br></td>'.
'<tr><td width="30%">Make :</td><td>'.
'<select name="make" id="make" onchange="populate()">';
foreach(array('Please Choose A Model', 'Zyxel', 'Nomadix', 'Proxim', 'Ascendance', 'BCEG') as $opt)
{
$selected = ($opt == $mk) ? ' selected' : '';
echo "<option value='$opt'$selected>$opt</option>\n";
}
echo '</SELECT>'.
'</td>'.
'</tr><tr>'.
'<td width="30%">Model :</td><td>'.
'<select name="model">'.
'<option>Please Select A Model</option>'.
'</SELECT>'.
'</td>'.
'</tr>'.
'<tr><td width="30%">Serial Number:</td><td><input type="text" name="sn" size="20" value="'. htmlspecialchars(stripslashes($sn)).'"></tr></td>'.
'<tr><td width="30%">Mac Address:</td><td><input type="text" name="mac" size="20" value="'. htmlspecialchars(stripslashes($ma)).'"></tr></td>'.
'<tr><td width="30%">IP Address:</td><td><input type="text" name="ipaddr" size="20" value="'. htmlspecialchars(stripslashes($ip)).'"></tr></td>'.
'<tr><td width="30%">Property ID:</td><td><input type="text" name="prop" size="7" value="'. htmlspecialchars(stripslashes($pp)).'"></tr></td>'.
'<tr><td width="30%">Property Contact Name/Title: </td><td><input type="text" name="contact" size="20" value="'. htmlspecialchars(stripslashes($ct)).'"></tr></td>'.
'<tr><td width="30%">Shipping:</td><td>'.
'<select name="ship" id="ship">';
foreach(array('Method of Shipping', 'Ground', 'Next Day Air', 'Next Day Saturday', '2nd Day', '3 day') as $opt2)
{
$selected = ($opt2 == $sp) ? ' selected' : '';
echo "<option value='$opt2'$selected>$opt2</option>\n";
}
echo '</SELECT></tr></td>'.
'<tr><td width="30%">Ticket#:</td><td><input type="text" name="ticket" size="7" value="'. htmlspecialchars(stripslashes($tt)).'"></tr></td>'.
'<tr><td width="30%">Comments:</td><td>'.
'<textarea name="status" rows="4" cols="40">'. htmlspecialchars(stripslashes($cm)).'</textarea></td></tr>'.
'</table><br>'.
'<input type="submit" name="submit" value="Submit Request">'.
'</form>';



}

?>

If you notice I have the actual form in there twice. Reason is cause im trying to do all this in one page instead of 2. Also could someone advise me a few sites to learn more advance form building? Thanks alot!!!