JQuery and PHP validation problem?
<p>I want to do the validation on my PHP side and then have my JQuery code display <code>your changes have been saved</code> when the submit button is clicked but the JQuery code states that the changes have been saved even when the validation fails.</p>

<p>How can i fix this so that PHP can do the validation and then JQuery can do its thing when PHP has finished its validation?</p>

<p>Here is my Jquery code.</p>

<pre><code>$(function() {
    $('#changes-saved').hide();
    $('.save-button').click(function() {
        $.post($('#contact-form').attr('action'), $('#contact-form').serialize(), function(html) {
            $('div.contact-info-form').html(html);
            $('#changes-saved').hide();
            $('#changes-saved').html('Your changes have been saved!').fadeIn(4000).show();
        });

        $('a').click(function () {
            $('#changes-saved').empty();
            $('#changes-saved').hide();
        });

        return false; // prevent normal submit
    });
});
</code></pre>

<p>Here is part of my PHP code.</p>

<pre><code>// Check for an email address:
if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $_POST['email'])) {
    $email = mysqli_real_escape_string($mysqli, strip_tags($_POST['email']));
} else {
    echo '&lt;p class="error"&gt;Please enter a valid email address!&lt;/p&gt;';
}
</code></pre>
