[jQuery] (validate) does not work with backup php validation
I'm using bassistance.de's form validation, as shown here:
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
In the very possible event that someone is browsing without JavaScript
enabled, I've put together a PHP form validation that should direct
the user to an error page (or thank you page upon success).
The JavaScript works when I do not have the validation part in the
PHP. When I do, it seems the JavaScript is completely ignored.
Here's my HTML:
<form action="form.php" method="post" id="contactform" class="form
extended contact">
<fieldset>
<legend>Contact</legend>
<p class="req"><strong>*</strong> Indicates a required field.</
p>
<ol>
<li class="name">
<label for="txt_name">Name <strong>*</strong></label>
<input id="txt_name" name="txt_name" class="text" />
</li>
<li class="email">
<label for="txt_email">Email Address <strong>*</strong></
label>
<input id="txt_email" name="txt_email" class="text" />
</li>
<li class="message">
<label for="txt_message">Message <strong>*</strong></label>
<textarea id="txt_message" name="txt_message"></textarea>
</li>
<input type="submit" name="send" value="Send"
class="submit" />
</ol>
</fieldset>
</form>
Here's my JS:
//initiate validator on load
$(function() {
// validate contact form on keyup and submit
$("#contactform").validate({
//set the rules for the field names
rules: {
txt_name: {
required: true,
minlength: 2
},
txt_email: {
required: true,
email: true
},
txt_message: {
required: true,
minlength: 2
},
},
//set messages to appear inline
messages: {
txt_name: "Please enter your name",
txt_email: "Please enter a valid email address",
txt_message: "Please enter your message"
}
});
});
and finally, here's my PHP:
<?php
// get posted data into local variables
$emailto = "me@me.com";
$subject = "Contact Form";
$name = Trim(stripslashes($_POST['txt_name']));
$email = Trim(stripslashes($_POST['txt_email']));
$message = Trim(stripslashes($_POST['txt_message']));
$today = date("F j, Y, g:i a");
// prepare email body text
$body = "";
$body .= $today;
$body .= "\n";
$body .= "\n";
$body .= "Name: ";
$body .= $name;
$body .= "\n";
$body .= "Email: ";
$body .= $email;
$body .= "\n";
$body .= "Message: ";
$body .= $message;
$body .= "\n";
$body .= "\n";
// check for empty fields
if ( $name OR $email OR $message != '' ) {
mail($emailto, $subject, $body, "From: <$email>", "-f me@me.com");
print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.php\" /