How to Use Javascript Popups to Display Gravity Forms Error Messages

225

Gravity Forms is potentially the most beginner friendly contact form out there. The best part of Gravity Forms though is its customizability. It allows even advanced users to make changes to its functionality. In a recent article we showed you how you could add placeholder text in Gravity Forms. In this article we are going to show you how you can customize the way error messages are displayed.

To do this open your functions.php file and paste the following code:

  add_filter( 'gform_validation_message', 'sw_gf_validation_message', 10, 2 );    function sw_gf_validation_message( $validation_message ) {  	add_action( 'wp_footer', 'sw_gf_js_error' );  }  function sw_gf_js_error() { ?>  	<script type="text/javascript">  		alert( "Oops, you must have forgotten something...fields marked with a * are required!" );  	</script>  <?php }  

You can change the error message by modifying what is inside the alert () function. Now, whenever someone forgets to fill something out the error message will display in javascript popups rather than above your Gravity Forms.

Gravity Forms Error Message

Credits: Brad Williams