I'm trying to use the ajax contact form i found from:
http://capsizedesigns.com/blog/2008/04/an-ultra-slick-ajax-contact-form-with-jquery/




PHP:
<?php
    error_reporting(E_NOTICE);

    function valid_email($str)
    {
        return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]
+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
    }

    if($_POST['name']!='' && $_POST['email']!='' &&
valid_email($_POST['email'])==TRUE && strlen($_POST['comment'])>1)
    {
        $to = "[EMAIL PROTECTED]";
        $headers =  'From: '.$_POST['email'].''. "\r\n" .
                'Reply-To: '.$_POST['email'].'' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();
        $subject = "Contact Form";
        $message = htmlspecialchars($_POST['comment']);

        if(mail($to, $subject, $message, $headers))
        {
            echo 1; //SUCCESS
        }
        else {
            echo 2; //FAILURE - server failure
        }
    }
    else {
        echo 3; //FAILURE - not valid email
    }
?>


And the js:

    $(document).ready(function(){
        $('#myForm').ajaxForm(function(data) {
            if (data==1){
                $('#success').fadeIn("slow");
                $('#myForm').resetForm();
            }
            else if (data==2){
                $('#badserver').fadeIn("slow");
            }
            else if (data==3)
            {
                $('#bademail').fadeIn("slow");
            }
        });
    });




What I want it to do is still be usable when javascript is disabled.
So I need to it output the actual error message though php instead of
the number. I can obviously change this really easy by just putting
the error message in the echo instead of there being the number. But
when I try to change the javascript to match the corresponding error
message, the whole script stops working.

I try putting data=="Please enter a valid email address."
It seems to me that it should work, but I am still new to javascript
and php so I could be making a stupid mistake. I would be grateful for
any help.

Reply via email to