Magento – callback I can use after a form has been validated

form-validationvalidation

I have to reflow the Foundation equalizer on a page that contains a form [contact page] – if validation failsthe form will overlap the footer with the added validation error elements.

<script type="text/javascript">
//<![CDATA[

    var contactForm = new VarienForm('contactForm', true);

    jQuery('#contact-submit').click(function(){
        console.log('submitted');
        jQuery(document).foundation('equalizer', 'reflow');
    });

//]]>
</script>

Obviously this only works after the submit button is clicked a second time.

Is there a callback function [or something] I can use after Magento have validated the form to call the Foundation reflow?

UPDATE

According to some different docs here and there, I'm supposed to be able to do something like this:

<script type="text/javascript">
//<![CDATA[
    var contactForm = new VarienForm('contactForm', {onFormValidate: myCallback, immediate : true});

    function myCallback(result, form) {
        console.log('callback = ' + result);
    }
//]]>
</script>

It will validate the form, but does not fire the callback OR validate immediately….

Best Answer

Yes you can validate your form explicitly and based on the status of the validation (success/failed) you can roll out your own callback actions. Hope am understanding you correctly and pointing you to the right direction.

<script type="text/javascript">
//<![CDATA[

    var contactForm = new VarienForm('contactForm', true);
    if (contactForm .validator.validate()){
        alert("Contact form is submitted and Validation Passed !"); //i love alerts more than console.log() as it works on all the browsers and versions
    }else{
        alert("Contact form is submitted and Validation Failed !");   
        jQuery(document).foundation('equalizer', 'reflow'); // assumed you have jQuery.noConflict(); before you call jQuery
    } 

//]]>
</script>