Form not submitting when trying to use jQuery's submitHandler
<p>I am converting a contact form to AJAX, so that I can do the success function. Right now the code is stopping at the submitHandler section saying that it is undefined. How is my submitHandler not defined?</p>

<p><code>submitHandler(function(form) {</code></p>

<p>Am I doing this in the correct way, though? I want to use my current php because I built it to be back-end validation on-top of the jQuery validation.</p>

<p>Does anyone see what is wrong with the submitHandler and anything that may be preventing this from sending?</p>

<p>HTML</p>

<pre><code>&lt;div class="contact-container"&gt;
    &lt;form id="contactform" method="post" action="" novalidate&gt;
        &lt;?php 
            if($sent === true) {
                echo "&lt;h2 class='success'&gt;Thanks, your message has been sent successfully&lt;/h2&gt;";
            } elseif($hasError === true) {
                echo '&lt;ul class="errorlist"&gt;';
                foreach($errorArray as $key =&gt; $val) {
                    echo "&lt;li&gt;" . ucfirst($key) . " field error - $val&lt;/li&gt;";
                }
                echo '&lt;/ul&gt;';
            }
        ?&gt;
        &lt;div&gt;
        &lt;input type="text" class="contact_input" name="name" id="name" value="&lt;?php echo (isset($name) ? $name : ""); ?&gt;" placeholder="Name"&gt;
        &lt;/div&gt;
        &lt;div&gt;
        &lt;input type="email" class="contact_input" name="email" id="email" value="&lt;?php echo (isset($email) ? $email : ""); ?&gt;" placeholder="Email"&gt;
        &lt;/div&gt;
        &lt;div&gt;
        &lt;textarea name="message" class="contact_input" id="message" placeholder="Message"&gt;&lt;?php echo (isset($message) ? $message : ""); ?&gt;&lt;/textarea&gt;
        &lt;/div&gt;
        &lt;input type="submit" id="submit_contact" class="clear" name="submitform" value="Send"&gt;
    &lt;/form&gt;
&lt;/div&gt;
&lt;div class="contact-email-success"&gt;
    &lt;div class="contact-email-success-container"&gt;
        &lt;div id="contact-email-success-title"&gt;THANK YOU FOR CONTACTING OUR AGENCY!&lt;/div&gt;
        &lt;div id="contact-email-success-description"&gt;Your submission has been received and one of our team members will contact you shortly.&lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>jQuery</p>

<pre><code>//Send the project email
$(document).ready(function(){ 
    $("#submit_contact").on("click", function (event) {
        //event.preventDefault();

        $("#contactform").validate({
            rules: {
                name: {
                    required: true,
                    minlength: 2
                },
                email: {
                    required: true,
                    email: true
                },
                message: {
                    required: true,
                    minlength: 5
                }
            },
            messages: {
                name: {
                    required: "Please enter your name",
                    minlength: "Your name seems a bit short, doesn't it?"
                },
                email: {
                    required: "Please enter your email address",
                    email: "Please enter a valid email address"
                },
                message: {
                    required: "Please enter your message",
                    minlength: "Your message seems a bit short. Please enter at least 5 characters"
                }
            }
        });

        submitHandler(function(form) {

            //Variables for the form ids
            var name    = $("#name").val();
            var email   = $("#email").val();
            var message = $("#message").val();


                $.ajax({
                    url: "email-contact.php", 
                    type: "POST",
                    data: {
                        "project_name": name,
                        "title_roll":   email,
                        "project_email": message
                    },
                    success: function (data) {
                        //console.log(data); // data object will return the response when status code is 200
                        if (data == "Error!") {
                            alert("Unable to send email!");
                            alert(data);
                        } else {
                            $(".contact-container").addClass("removeClass");
                            $(".contact-email-success").show();
                            $(".announcement_success").fadeIn();
                            $(".announcement_success").show();
                           // $('.announcement_success').html('Email Successfully sent!');
                           //$('.announcement_success').delay(5000).fadeOut(400);
                        }
                    },
                    error: function (xhr, textStatus, errorThrown) {
                        alert(textStatus + "|" + errorThrown);
                        //console.log("error"); //otherwise error if status code is other than 200.
                    }
                });
        }); 
    });
});
</code></pre>

<p>PHP</p>

<pre><code>$hasError = false;
$sent = false;

$name       = $_POST['name'];
$email      = $_POST['email'];
$message    = $_POST['message'];

if(isset($_POST['submitform'])) {
    $name = trim(htmlspecialchars($_POST['name'], ENT_QUOTES));
    $email = trim(htmlspecialchars($_POST['email']));
    $message = trim(htmlspecialchars($_POST['message'], ENT_QUOTES));

    $fieldsArray = array(
        'name' =&gt; $name,
        'email' =&gt; $email,
        'message' =&gt; $message
    );

    $errorArray = array();

    foreach($fieldsArray as $key =&gt; $val) {
        switch ($key) {
            case 'name':
            case 'message':
            if(empty($val)) {
                $hasError = true;
                $errorArray[$key] = ucfirst($key) . " field was left empty.";
            }
            break;
            case 'email':
                if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                    $hasError = true;
                    $errorArray[$key] = "Invalid Email Address entered";
                } else {
                    $email = filter_var($email, FILTER_SANITIZE_EMAIL);
                }
                break;
        }
    }

    if($hasError !== true) {
        $to = "gsdfa";
        $subject = "Contact Form Submitted";
        $msgcontents = "Name: $name&lt;br&gt;Email: $email&lt;br&gt;Message: $message";
        $headers = "MIME-Version: 1.0 \r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
        $headers .= "From: $name &lt;$email&gt; \r\n";
        $emailsent = mail($to, $subject, $msgcontents,$headers);
        if($mailsent) {
            $sent = true;
            unset($name);
            unset($email);
            unset($message);
        }
    }
}
</code></pre>