I have the following form that I need the fields to be mandatory before submission:
form name="application" id="applicatipn" method="post" action="send_mail.php" >
<h2 class="title">form</h2>
<p class="sub-text">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
</p>
<table width="620px">
<tr class="bg-grey">
<td>
<h3 >Personal Details</h3>
</td>
</tr>
</table>
<table width="600px" class="bg-light-grey" style=" margin-left: 10px">
<tr>
<td valign="top">
<label>Title</label>
<br />
<input type="text" name="title" size="5" class="auto-width" />
<br />
<br />
</td>
</tr>
<tr class="no-margin-bottom">
<td valign="top">
<label>Forenames</label>
<br />
<input type="text" class="no-margin-bottom" name="forename" size="30" />
</td>
</tr>
<tr>
<td valign="top">
<label>Surname</label>
<br />
<input type="text" name="surname" size="30" />
<br />
<br />
</td>
</tr>
<tr>
<td valign="top">
<label>Address</label>
<br />
<input type="text" name="address1" size="30" />
<br />
<input type="text" name="adress2" size="30" />
</td>
</tr>
<tr>
<td valign="top">
<label>City</label>
<br />
<input type="text" name="city" size="30" class="auto-width" />
</td>
</tr>
<tr>
<td valign="top">
<label>Postcode</label>
<br />
<input type="text" name="postcode" size="10" class="auto-width" />
<br />
<br />
</td>
</tr>
<tr>
<td valign="top">
<label>Telephone No</label>
<br />
<input type="text" name="telephone" size="30" placeholder=" + 4 4 " />
<br />
<br />
</td>
</tr>
<tr>
<td valign="top">
<label>National Insurance Number *</label>
<br />
<input type="text" name="insurance_num" size="30" class="auto-width" />
</td>
</tr>
<tr>
<td valign="top">
<label>Date Of Birth</label>
<br />
<input type="text" name="dob" size="12" class="auto-width" placeholder=" D D M M Y Y "/>
<br />
<br />
</td>
</tr>
<tr>
<td valign="top">
<label>Email Address *</label>
<br />
<input type="text" name="email" size="30" style="width:55%" />
<br />
<br />
</td>
</tr>
</table>
<table width="620px">
<tr class="bg-grey">
<td>
<h3 >Loan Information</h3>
</td>
</tr>
</table>
<table width="600px" class="bg-light-grey" style="margin-left: 10px">
<tr>
<td valign="top">
<br />
<label>XXXXXXXXXXXXXXXXXXXX</label>
<br />
<span> @ </span> <input type="text" name="loan_amount" size="5" class="auto-width" />
<br />
<br />
</td>
</tr>
</table>
<table width="620px">
<tr class="bg-grey">
<td>
<h3 >Terms & Conditions</h3>
</td>
</tr>
</table>
<table width="600px" style="margin-left: 10px">
<tr>
<td valign="top" style="border: 1px solid">
<p style="font-size: 10px; margin: 5px 5px 5px 5px; font-weight: 500; padding:10px 0px">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</p>
</td>
</tr>
<tr>
<td>
<p style="text-align: center; font-size: 9px;font-weight:bold">XXXXXXXXXXXXXXXXXXXXXXXXXX</p>
</td>
</tr>
</table>
<table width="620px">
<tr class="bg-grey">
<td>
<h3 >Customers Signature</h3>
</td>
</tr>
</table>
<table width="600px" style="background-color: #c1c1c1; margin-left: 10px;border: 1px solid">
<tr>
<td valign="top" >
<br />
<input type="text" class="signature" name="signature" size="15" placeholder="Signature" style="border: 1px solid"/>
</td>
</tr>
</table>
<table width="620px">
<tr class="bg-grey">
<td style="text-align:center;">
<input type="submit" name="submit" id="submit">
</td>
</tr>
</table>
</div>
</form>
The PHP:
<?php
if(isset($_POST['submit']))
{
$title=$_POST['title'];
$forename=$_POST['forename'];
$surname=$_POST['surname'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$city=$_POST['city'];
$postcode=$_POST['postcode'];
$telephome=$_POST['telephone'];
$insurance_num=$_POST['insurance_num'];
$dob=$_POST['dob'];
$email_id=$_POST['email'];
$loan_amount=$_POST['loan_amount'];
$signature=$_POST['signature'];
$to = 'XXXXXXXXXXXXXXXXXXXX';
$subject = 'From Website';
$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Title:</strong> </td><td>" . strip_tags($_POST['title']) . "</td></tr>";
$message .= "<tr><td><strong>Forename:</strong> </td><td>" . strip_tags($_POST['forename']) . "</td></tr>";
$message .= "<tr><td><strong>Surname:</strong> </td><td>" . strip_tags($_POST['surname']) . "</td></tr>";
$message .= "<tr><td><strong>Address:</strong> </td><td>" . strip_tags($_POST['address1']) . "</td></tr>";
$message .= "<tr><td><strong>Address:</strong> </td><td>" . strip_tags($_POST['address2']) . "</td></tr>";
$message .= "<tr><td><strong>City:</strong> </td><td>" . strip_tags($_POST['city']) . "</td></tr>";
$message .= "<tr><td><strong>Post code:</strong> </td><td>" . strip_tags($_POST['postcode']) . "</td></tr>";
$message .= "<tr><td><strong>Telephone:</strong> </td><td>" . strip_tags($_POST['telephone']) . "</td></tr>";
$message .= "<tr><td><strong>Insurance Numebr:</strong> </td><td>" . strip_tags($_POST['insurance_num']) . "</td></tr>";
$message .= "<tr><td><strong>Date of birth:</strong> </td><td>" . strip_tags($_POST['dob']) . "</td></tr>";
$message .= "<tr><td><strong>Email id:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$message .= "<tr><td><strong>Loan Amount:</strong> </td><td>" . strip_tags($_POST['loan_amount']) . "</td></tr>";
$message .= "<tr><td><strong>Signature:</strong> </td><td>" . $_POST['signature'] . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
if(mail($to, $subject, $message, $headers))
{
echo '<script> alert("Submit successfully")</script>';
echo '<script> location.href="index.html" </script>';
}
else
{
echo '<script> alert("Mail not send! Please again try!")</script>';
echo '<script> location.href="apply.html"</script>';
}
}
else
{
echo '<script> location.href="xxx.html"</script>';
}
?>
Thanks in advance