Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Use Javascript Popups to Display Gravity Forms Error Messages

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Use Javascript Popups to Display Gravity Forms Error Messages

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!" );
<?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

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. Bruce Prock says:

    …not sure this code works with the current versions of wp and gravity forms.

  2. bodan dalia says:

    I am not able to use this method. If I return the js code as the result of sw_gf_validation_message function i have the alert. But otherwise the java code is never called.
    I am trying to activate a dialog when an validation fails, but if i use the method i mention, the js document is empty and i can;t access the dialog :(

  3. Streamingdb says:

    It’s possible, do the same thing for the confirmation message?

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.