Validation does not work with PHP
<p>I am having problem to see the problem with a pre-scripted template.
There are 3 files as follows,</p>

<pre><code>/contact.php
/forms/contact.php
/js/forms.js
</code></pre>

<p>So when a visitor fills up the contact.php in root directory it redirects to /forms/contact.php and forms.js checks the form and if there is no problem sends an email.</p>

<p>Here is my /contact.php which includes the form,</p>

<pre><code>&lt;form id="contactform" method="post" action="forms/contact.php"&gt;
&lt;div class="divide10"&gt;&lt;/div&gt;
&lt;input id="name" name="name" value="Your Name" type="text" class="prepared-input"&gt;
&lt;div class="divide15"&gt;&lt;/div&gt;
&lt;input id="email" name="email" value="Your Email" type="text" class="prepared-input"&gt;
&lt;div class="divide15"&gt;&lt;/div&gt;
&lt;textarea  id="contactmessage" name="message" rows="3" class="prepared-input"&gt;Your Message&lt;/textarea&gt;
&lt;div class="divide15"&gt;&lt;/div&gt;
&lt;input type="submit" id="From_Comment_Go" value="Send Message " class="btn maincolor small"&gt;
&lt;span class="errormessage   hiddenatstart"&gt;Error! Please correct marked fields.&lt;/span&gt;
&lt;span class="successmessage   hiddenatstart"&gt;Message send successfully!&lt;/span&gt;
&lt;span class="sendingmessage   hiddenatstart"&gt;Sending...&lt;/span&gt;
&lt;/form&gt;
</code></pre>

<p>Here is my /forms/contact.php</p>

<pre><code>&lt;?php
$to = 'example@mail.com';


//Language Options
$contact_labelmailhead = 'Contact Form Email';
$contact_labelmailsubject = 'Contact Form Email from';
$contact_labelname = 'Name';
$contact_labelemail = 'Email';
$contact_labelmessage = 'Message';

$name = trim($_POST['name']);
$email = trim($_POST['email']);
$message = str_replace(chr(10), "&lt;br&gt;", $_POST['message']);

$body = "&lt;html&gt;&lt;head&gt;&lt;title&gt;$contact_labelmailhead&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;br&gt;";
$body .= "$contact_labelname: &lt;b&gt;" . $name . "&lt;/b&gt;&lt;br&gt;";
$body .= "$contact_labelemail &lt;b&gt;" . $email . "&lt;/b&gt;&lt;br&gt;";
$body .= "$contact_labelmessage:&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;b&gt;" . $message . "&lt;/b&gt;&lt;br&gt;";
$body .= "&lt;br&gt;&lt;/body&gt;&lt;/html&gt;";

$subject = $contact_labelmailsubject.' ' . $name;
$header = "From: $email\n" . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=utf-8\n";

mail($to, $subject, $body, $header);


?&gt;
</code></pre>

<p>and lastly forms.js is here,</p>

<pre><code>jQuery(document).ready(function() { 
    /* Contact Form */
    if(jQuery('#contactform').length != 0){
        addForm('#contactform');
    }

    /* Quick Contact */
    if(jQuery('#quickcontact').length != 0){
        addForm('#quickcontact');
    }

    /* Blog Comments */
    if(jQuery('#replyform').length != 0){
        addForm('#replyform');
    }
});

    function addForm(formtype) {
    var formid = jQuery(formtype);
    var emailsend = false;

    formid.find("input[type=submit]").click(sendemail);


    function validator() {

        var emailcheck = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        var othercheck = /.{4}/;
        var noerror = true;

        formid.find(".requiredfield").each(function () {

            var fieldname = jQuery(this).attr('name');
            var value = jQuery(this).val();
            if(value == "Name *" || value == "Email *" || value == "Message *"){
                value = ""; 
            }

            if(fieldname == "email"){
                if (!emailcheck.test(value)) {
                    jQuery(this).addClass("formerror");
                    noerror = false;
                } else {
                    jQuery(this).removeClass("formerror");
                }   
            }else{
                if (!othercheck.test(value)) {
                    jQuery(this).addClass("formerror");
                    noerror = false;
                } else {
                    jQuery(this).removeClass("formerror");
                }   
            }
        })

        if(!noerror){
            formid.find(".errormessage").fadeIn();
        }

        return noerror;
    }

    function resetform() {
        formid.find("input").each(function () {
            if(!jQuery(this).hasClass("button")) jQuery(this).val("");  
        })
        formid.find("textarea").val("");
        emailsend = false;
    }


    function sendemail() {
        formid.find(".successmessage").hide();
        var phpfile = "";
        if(formtype=="#contactform"){
            phpfile = "forms/contact.php";
        }else if(formtype.lastIndexOf("c_")){
            phpfile = "forms/quickcontact.php";
        }else{
            phpfile = "";
        }
        if (validator()) {
            if(!emailsend){
                emailsend = true;
                formid.find(".errormessage").hide();
                formid.find(".sendingmessage").show();
                jQuery.post(phpfile, formid.serialize(), function() {
                    formid.find(".sendingmessage").hide();
                    formid.find(".successmessage").fadeIn();
                    if(!formtype.lastIndexOf("c_"))resetform();
                });
            }
        } 
        return false
    }
</code></pre>

<p>}</p>

<p>So, leaving the form sends Values :S and does not check anything. Shall I try to fix this or try to implement something else? I am not that into jQuery and cannot say if there is something wrong with validation script.</p>

<p>Some advice would be great!
Thank you!</p>
