In: Computer Science
Using PHP, Create a form that uses the method POST to send the
information. The form should capture the distance the package needs
to travel with the one field for the distance in miles.
All fields should have the REQUIRED attribute.
The form should have a submit button and reset button.
The form should look nice. All the labels should line up
horizontally and all the
INPUTS/SELECT should line up horizontally.
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
$distanceErr = $originError = $primeError = $destinationError =
"";
$distance = $origin = $prime = $specialInstructions = $destination
= "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["distance"])) {
$distanceErr = "distance is mandatory";
}
if (empty($_POST["origin"])) {
$originErr = "origin is mandatory";
}
if (empty($_POST["destination"])) {
$destinationError = "destination is mandatory";
}
if (empty($_POST["prime"])) {
$primeError = "Please select delivery type";
}
}
?>
<h2>Package Handler</h2>
<p><span class="error">* required
field</span></p>
<form method="post" action="<?php echo
htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table>
<tr>
<td>
Package Distance:
</td><td><input type="text" name="distance"
value="<?php echo $distance;?>">
<span class="error">* <?php echo
$distanceErr;?></span>
</td></tr>
<tr>
<td>
Origin:</td>
<td><input type="text" name="origin" value="<?php echo
$origin;?>">
<span class="error">* <?php echo
$originError;?></span>
</td></tr>
<tr>
<td>
Destination:
</td>
<td><input type="text" name="destination" value="<?php
echo $destination;?>">
<span class="error"><?php echo
$destinationError;?></span>
</td>
</tr>
<tr>
<td>Special Instructions:</td>
<td><textarea name="specialInstructions" rows="5"
cols="40"><?php echo
$specialInstructions;?></textarea>
</td></tr>
<tr><td>Prime Delivery:</td>
<td><input type="radio" name="prime"
value="Yes">Yes
<input type="radio" name="prime" value="No">No
<span class="error">* <?php echo
$primeError;?></span>
</td></tr>
<tr><td colspan="2" style="text-align:center;">
<input type="submit" name="submit"
value="Submit"></td></tr>
</table>
</form>
</body>
</html>