I've been looking for over 2 days for solution to this problem of mine. Went through all the related posts on stack, but no luck. I have a form that accepts data, then passes on to a php procedure to process it which in turn calls on a html thank you page. I am not at all familiar with Javascript or JQuery but can make it work after spending some time. I am posting the codes here along with many suggestions that I tried to no avail. Any help that ends my misery is appreciated. Thanks.
HTML
<form method='post' action='contact-form-proc.php' name='contactform' id='contactform' onsubmit="setTimeout('clear_form()',200);return true">
<p>
<label for='fullname'>Your Name:</label><br/>
<input type='text' name='fullname' />
</p>
<p>
<label for='email' >Email Address:</label><br/>
<input type='text' name='email' />
</p>
<p>
<label for='mobile' >Mobile:</label><br/>
<input type='text' name='mobile' />
</p>
<p>
<label for='checkIndate' >Check in Date:</label><br/>
<input type='text' name='checkIndate'/>
</p>
<p>
<label for='comment' >Comment:</label><br/>
<textarea name='comment' cols='25' rows='3'></textarea>
</p>
<input type="image" src="submit.gif" name="submit"/>
<!--<input type='submit' name='submit' value='' id="submit" />-->
<input type="hidden" name="submit" value="Submit"/>
</form>
PHP
<?php
if(empty($_POST['submit']))
{
echo "Form is not submitted!";
exit;
}
if(empty($_POST["fullname"]) ||
empty($_POST["email"]))
{
echo "Please fill the form";
exit;
}
$name = $_POST["fullname"];
$email = $_POST["email"];
$mobile = $_POST["mobile"];
$checkindate = $_POST["checkIndate"];
$comment = $_POST["comment"];
mail( 'xxx@xxxxxx.com' , 'New form submission' , "New form submission: Name: $name, Email:$email, Mobile: $mobile, CheckIndate:$checkIndate, Comment:$comment" );
header('Location: thank-you.html');
?>
These are what I tried:
<script type="text/javascript">
/*$('#contactform').trigger("reset");*/
function clear_form() {
/* document.contactform.reset();
document.getElementById("contactform").reset();*/
/*$(window).load(function() {
$('#contactform input[type="text"]').val('');*/
$(window).load(function() {
$('#contactform').children('input').val('');
}
});
}
</script>