[solved] Gravity Forms with Javascript Validation

September 17, 2015

Gravity Forms (www.gravityforms.com), without a doubt is one of the best WordPress forms plugin out there, I have been using it since it was launched and is a brilliant tool and I have it in use on literally hundreds of web sites.

However, recently I have had the need to put javascript validation on someĀ forms and unfortunately, Gravity forms does not natively support it.

When I contacted Gravity Support to ask about javascript validation, they basically told me its not supported and I was on my own.

So below, is some jquery code I have scrapped together to get it working.

gravity-form-javascript-validation

Just assume that the form is Form ID is 7, the rest should be self explanatory.

The code can be put anywhere you like as long as it’s before the Gravity Form function call.

<!-- For Gravity Forms Validation Top Form -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script>
jQuery(document).ready(function() {
jQuery("#gform_submit_button_7").click(function() {
return GravityFormValidation_7(gform_7);
});
});

function GravityFormValidation_7(Form){

if (Form.input_7_1_3.value == “”){
alert(“Please enter your Name”);
Form.input_7_1_3.focus();
return (false);
}

if (Form.input_7_2.value == “”){
alert(“Please enter your Phone Number”);
Form.input_7_2.focus();
return (false);
}

if (Form.input_7_4.value == “”){
alert(“Please enter your Email Address.”);
Form.input_7_4.focus();
return (false);
}

}
</script>