Hello,
I’ve created a simple html form which will POST to a php mail() script.
The HTML is pretty straightforward, but I will include it here for reference.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>
Installation Checklist
</title>
</head>
<body>
<h1>
Installation Checklist
</h1>
<form name="checklist" action="checklist.php" method="post">
<table>
<tr>
<td>
Job Name: <input type="text" name="name" />
</td>
<td>
Account Number: <input type="text" name="account" />
</td>
</tr>
<tr>
<td>
Street Address: <input type="text" name="address" />
</td>
</tr>
<tr>
<td>
City: <input type="text" name="city" />
State: <input type="text" name="state" maxlength="2" size="2" value="MN" />
</td>
<td>
Zip Code: <input type="text" name="zip" size="10" />
</td>
</tr>
<tr>
<td>
Panel Phone Number - Primary: <input type="text" name="primary" size="13" />
</td>
<td>
Panel Phone Number - Alternate: <input type="text" name="alternate" size="13" />
</td>
</tr>
<tr>
<td>
Installer Name(s): <input type="text" name="installer" />
</td>
</tr>
</table>
<h2>
Panel
</h2>
<input type="checkbox" name="box1" value="yes" />Panel is securely mounted.
<br />
<input type="checkbox" name="box2" value="yes" />Panel is mounted on plywood if needed. (e.g. outer cement wall.)
<br />
<input type="checkbox" name="box3" value="yes" />Panel is grounded as required (cold water pipe, minimum 14AWG Solid Wire.)
<h2>
Proper Wire Use
</h2>
<input type="checkbox" name="box4" value="yes" />18/2 for A/C power, sirens, door strikes.
<br />
<input type="checkbox" name="box5" value="yes" />18AWG Fire Wire for initiating devices.
<br />
<input type="checkbox" name="box6" value="yes" />14AWG Fire Wire for notification devices.
<br />
<input type="checkbox" name="box7" value="yes" />If shielded wire is used, shields are secured at panel end.
<br />
<input type="checkbox" name="box8" value="yes" />Plenum wire used as required.
<h2>
Proper Wire Run
</h2>
<input type="checkbox" name="box9" value="yes" />Wires properly and independently supported.
<br />
<input type="checkbox" name="box10" value="yes" />Wires taut, secured, and cable tie ends cut off.
<br />
<input type="checkbox" name="box11" value="yes" />Wire runs are neat, corners are 90 degrees.
<br />
<input type="checkbox" name="box12" value="yes" />Wires are clearly marked in panel and wiring information is provided.
<h2>
Miscellaneous
</h2>
<input type="checkbox" name="box13" value="yes" />Wire connections are tight at terminals and proper connectors are used.
<br />
<input type="checkbox" name="box14" value="yes" />Power transformer is secured properly.
<br />
<input type="checkbox" name="box15" value="yes" />All devices mounted securely and straight/level.
<br />
<input type="checkbox" name="box16" value="yes" />Panel and device paperwork left in panel.
<br />
<input type="checkbox" name="box17" value="yes" />Fire signs in place as needed.
<br />
<input type="checkbox" name="box18" value="yes" />Security sticker placed on door of panel.
<br />
<input type="checkbox" name="box19" value="yes" /> Security stickers placed on doors and windows; all competitor stickers removed.
<br />
<input type="checkbox" name="box20" value="yes" />Panel key left on top of panel, or given to customer.
<h2>
Testing
</h2>
<input type="checkbox" name="box21" value="yes" />Zoning info sent to Office and/or Central Station.
<br />
<input type="checkbox" name="box22" value="yes" />Test ALL devices (smokes, sirens, doors, motions, etc.)
<br />
<input type="checkbox" name="box23" value="yes" />Test proper operation of all zones.
<br />
<input type="checkbox" name="box24" value="yes" />Check that PROPER SIGNALS were received at the Central Station.
<h2>
Customer Hand-Off
</h2>
<input type="checkbox" name="box25" value="yes" />Customer trained on system use including adding and changing codes.
<br />
<input type="checkbox" name="box26" value="yes" />Customer has received zone information.
<br />
<input type="checkbox" name="box27" value="yes" />Customer has received User Manuals and Dispatch Cards.
<h2>
Complete
</h2>
<input type="checkbox" name="box28" value="yes" />Installation is complete.
<br />
Date: <input type="text" name="date" />
<br />
<br />
<br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
I tried to use name=“box[]” instead of having each separate, but I’m not sure how to handle unchecked boxes in the array since the HTML will only POST a value if it’s checked and I couldn’t wrap my head around making it work another way.
Anyways, here is my PHP code.
[php]
<?php $to = "[email protected]"; $from = "[email protected]"; $headers = "From:" . $from; $subject = "Installation Checklist"; $fields = array(); $fields{"name"} = "Job Name"; $fields{"account"} = "Account Number"; $fields{"address"} = "Street Address"; $fields{"city"} = "City"; $fields{"state"} = "State"; $fields{"zip"} = "Zip"; $fields{"primary"} = "Primary Phone"; $fields{"alternate"} = "Alternate Phone"; $fields{"installer"} = "Installer Name"; $fields{"date"} = "Completed Date"; if(isset($_POST['box1'])) {$a1 = 'Yes';} else {$a1 = 'No';} if(isset($_POST['box2'])) {$a2 = 'Yes';} else {$a2 = 'No';} if(isset($_POST['box3'])) {$a3 = 'Yes';} else {$a3 = 'No';} if(isset($_POST['box4'])) {$a4 = 'Yes';} else {$a4 = 'No';} if(isset($_POST['box5'])) {$a5 = 'Yes';} else {$a5 = 'No';} if(isset($_POST['box6'])) {$a6 = 'Yes';} else {$a6 = 'No';} if(isset($_POST['box7'])) {$a7 = 'Yes';} else {$a7 = 'No';} if(isset($_POST['box8'])) {$a8 = 'Yes';} else {$a8 = 'No';} if(isset($_POST['box9'])) {$a9 = 'Yes';} else {$a9 = 'No';} if(isset($_POST['box10'])) {$a10 = 'Yes';} else {$a10 = 'No';} if(isset($_POST['box11'])) {$a11 = 'Yes';} else {$a11 = 'No';} if(isset($_POST['box12'])) {$a12 = 'Yes';} else {$a12 = 'No';} if(isset($_POST['box13'])) {$a13 = 'Yes';} else {$a13 = 'No';} if(isset($_POST['box14'])) {$a14 = 'Yes';} else {$a14 = 'No';} if(isset($_POST['box15'])) {$a15 = 'Yes';} else {$a15 = 'No';} if(isset($_POST['box16'])) {$a16 = 'Yes';} else {$a16 = 'No';} if(isset($_POST['box17'])) {$a17 = 'Yes';} else {$a17 = 'No';} if(isset($_POST['box18'])) {$a18 = 'Yes';} else {$a18 = 'No';} if(isset($_POST['box19'])) {$a19 = 'Yes';} else {$a19 = 'No';} if(isset($_POST['box20'])) {$a20 = 'Yes';} else {$a20 = 'No';} if(isset($_POST['box21'])) {$a21 = 'Yes';} else {$a21 = 'No';} if(isset($_POST['box22'])) {$a22 = 'Yes';} else {$a22 = 'No';} if(isset($_POST['box23'])) {$a23 = 'Yes';} else {$a23 = 'No';} if(isset($_POST['box24'])) {$a24 = 'Yes';} else {$a24 = 'No';} if(isset($_POST['box25'])) {$a25 = 'Yes';} else {$a25 = 'No';} if(isset($_POST['box26'])) {$a26 = 'Yes';} else {$a26 = 'No';} if(isset($_POST['box27'])) {$a27 = 'Yes';} else {$a27 = 'No';} if(isset($_POST['box28'])) {$a28 = 'Yes';} else {$a28 = 'No';} $message = "Installation Checklist \n\n"; foreach($fields as $a => $b) $message .= sprintf("%s: %s\n",$b,$_REQUEST[$a]); $message .= sprintf("\n\n"); $message .= sprintf("Panel is securely mounted: %s\n",$a1); $message .= sprintf("Panel is mounted on plywood if needed:%s\n",$a2); $message .= sprintf("Panel is grounded as required: %s\n",$a3); $message .= sprintf("\n\n"); $message .= sprintf("18-2 for AC power, sirens, door strikes: %s\n",$a4); $message .= sprintf("18AWG Fire Wire for initiating devices: %s\n",$a5); $message .= sprintf("14AWG Fire Wire for notification devices: %s\n",$a6); $message .= sprintf("If shielded wire is used, shields are secured at panel end: %s\n",$a7); $message .= sprintf("Plenum wire used as required: %s\n",$a8); $message .= sprintf("\n\n"); $message .= sprintf("Wires properly and independently supported: %s\n",$a9); $message .= sprintf("Wires taut, secured, and cable tie ends cut off: %s\n",$a10); $message .= sprintf("Wire runs are neat, corners are 90 degrees: %s\n",$a11); $message .= sprintf("Wires are clearly marked in panel and wiring information is provided: %s\n",$a12); $message .= sprintf("\n\n"); $message .= sprintf("Wire connections are tight at terminals and proper connectors are used: %s\n",$a13); $message .= sprintf("Power transformer is secured properly: %s\n",$a14); $message .= sprintf("All devices mounted securely and straight/level: %s\n",$a15); $message .= sprintf("Panel and device paperwork left in panel: %s\n",$a16); $message .= sprintf("Fire signs in place as needed: %s\n",$a17); $message .= sprintf("Security sticker placed on door of panel: %s\n",$a18); $message .= sprintf("Security stickers placed on doors and windows; all competitor stickers removed: %s\n",$a19); $message .= sprintf("Panel key left on top of panel, or given to customer: %s\n",$a20); $message .= sprintf("\n\n"); $message .= sprintf("Zoning info sent to Office and-or Central Station: %s\n",$a21); $message .= sprintf("Test ALL devices: %s\n",$a22); $message .= sprintf("Test proper operation of all zones: %s\n",$a23); $message .= sprintf("Check that PROPER SIGNALS were received at the Central Station: %s\n",$a24); $message .= sprintf("\n\n"); $message .= sprintf("Customer trained on system use including adding and changing codes: %s\n",$a25); $message .= sprintf("Customer has received zone information: %s\n",$a26); $message .= sprintf("Customer has received User Manuals and Dispatch Cards: %s\n",$a27); $message .= sprintf("Installation is complete: %s\n",$a28); $send = mail( $to, $subject, $message, $headers); if($send) {print "Your form was submitted, you can close this window"; } else {print "There was an error sending your mail, please notify [email protected]"; } ?>[/php]
It works, but I’d like to clean it up and make more modular so I can make similar forms easier.
I’m particularly interested if there’s a way to generate the if(isset()) section with some sort of for() loop
Thanks for taking time to look!