Hi i am making a contact form, i have done my validatin checks but what i want to do is that if a user leaves a field empty they will be provided with the error of the textbox that is left empty, but all their other information they have entered previously to remain in the textoxes so they do not have to re-enter it everytime they make a mistake.
my code is as follows:
<?php
if (isset($_POST['name']))
{
$name = $POST['name'];
$email = $POST['email'];
$mobile = $POST['mobile'];
$message = $POST['message'];
$error = "";
if (!$name) {
$error .= " *Name <br />";
}
if (!$email) {
$error .= " *Email <br />";
}
if (!$mobile) {
$error .= " *Phone <br />";
}
if (!$message) {
$error .= " *Message <br />";
}
if ($error !="") {
echo "Please fill out the following fields: <br />$error";
}
else{
echo "Your message has been successfully sent";
}
}
?>
<form action="contactus.php" method="POST">
<table>
<tr>
<td><div align="right"><span class="style4">Name: </span></div></td>
<td><input type="text" name="name" value="<?php echo $name ?>"></td>
</tr>
<tr>
<td><div align="right"><span class="style4">Email: </span></div></td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td><div align="right"><span class="style4">Phone No: </span></div></td>
<td><input type="text" name="mobile" /></td>
</tr>
<tr>
<td><div align="right"><span class="style4">Message: </span></div></td>
<td><textarea cols="50" rows="6" name="message"></textarea></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="submit" value="Submit form" />
<input type="reset" name="reset" value="Reset form" />
</td>
</tr>
</table>
</form>
thanks in advance!
Raj