TutorialUser Friendly Error Message Gravity Forms

Do you want to change the standard error text (when people did something wrong on your form). It looks quite unfriendly, the standard validation error. So let’s make it a little bit more friendly. You find the PHP and CSS code you need to do just that.

Change text error message

You can change the text of the Gravity Forms 2.5 and later error message by adding the following PHP text to your functions.php file in your WordPress theme directory.

/**
 * Changing default error message Gravity Forms (GF2.5)
 */
add_filter("gform_validation_message", "gwp_change_message", 10, 2);
function gwp_change_message($message, $form){
	return '<h2 class="gform_submission_error hide_summary">
				<span class="gform-icon gform-icon--close"></span>
				Oops, something was not correct. 
				Please review the highlighted fields below.
			</h2>';
}

Styling Error message in Gravity Forms 2.5 and later

This is how the standard (default) GF validation error in GF 2.5 and later looks like.

Change colors

If you want to change the color of the background and the border line of the message at the top, use this CSS to override. You can also change the shadow effect (we left it here the same).

Notice that we’ve added body in front of the .gform_wrapper. You can also place the CSS without body in front of it, but be sure that this custom CSS is loaded later than the Gravity Forms default styling. Or you can add !important, but this makes it harder if you want to style error message differently on different places on your site.

/* Changing background and border color of top error message div */
body .gform_wrapper .gform_validation_errors {
    background: #ddecf5;
    border: 1.5px solid #65a9cb;
    box-shadow: 0 1px 4px rgb(0 0 0 / 11%), 0 0 4px rgb(18 25 97 / 4%);
}

It will look like this now:

We don’t want to use such a bright red color, so we also will change the color of the text. You can do that by adding this CSS:

/* Changing font color of top error message */
body .gform_wrapper .gform_validation_errors>h2 {
    color: #212529;
}

This is how we want it:

But we also want to change the red colors in the highlighted fields itself:

To do that, we can add the following CSS to our custom theme or in the customizer of the WordPress website:

/* Changing font color of error texts in form fields */
body .gform_wrapper .gfield_error .gfield_repeater_cell label, 
body .gform_wrapper .gfield_error label, 
body .gform_wrapper .gfield_error legend, 
body .gform_wrapper .gfield_validation_message, 
body .gform_wrapper .validation_message, 
body .gform_wrapper [aria-invalid=true]+label, .gform_wrapper label+[aria-invalid=true] {
    color: #212529;
}

/* Changing background and border of error div under field */
body .gform_wrapper .gfield_validation_message, 
body .gform_wrapper .validation_message {
    background: #ddecf5;
    border: 1px solid #65a9cb;
}

This looks much nicer and in line with our theme:

Use SCSS

You can also achieve the same as the above CSS code with the more readable SCSS code here:

body .gform_wrapper {

    /* Changing background and border color of top error message div */
    .gform_validation_errors {
        background: $secondary;
        border: 1.5px solid $primary;
        box-shadow: 0 1px 4px rgb(0 0 0 / 11%), 0 0 4px rgb(18 25 97 / 4%);

        /* Changing font color of top error message */
        &>h2 {
            color: $black;
        }
    }

    /* Changing font color of error texts in form fields */
    .gfield_error {
        .gfield_repeater_cell label,
        label,
        legend {
            color: $black;
        }
    } 

    [aria-invalid=true]+label, .gform_wrapper label+[aria-invalid=true] {
        color: $black;
    }

    /* Changing background and border of error div under field */
    .gfield_validation_message, 
    .validation_message {
        color: $black;
        background: $secondary;
        border: 1px solid $primary;
    }

}

Gravity Forms 2.4 and earlier

Gravity Forms 2.4 has a different styling, so you’ll need to use different PHP and CSS for 2.4 and earlier.

Changing error message with PHP in 2.4 and earlier

/**
 * Changing default error message Gravity Forms (GF2.4)
 */
function gwp_change_message($message, $form){
	return '<div class="validation_error">
				Please adjust the blue fields below.
			</div>';
}

Standard Gravity Forms validation error

This is how the standard (default) GF validation error in GF 2.4 and earlier looks like.

New (more friendly) Gravity Forms validation error

Now we want to create a more friendly and visually attractive error message for Gravity Forms.

Changing the looks (CSS)

You can change the looks by adding the following CSS code to your custom style.css file in your WordPress theme directory.

.gform_wrapper div.validation_error {
color: #000 !important;
font-size: 100% !important;
font-weight: normal !important;
border: 1px solid #65A9CC !important;
padding: 1em 0px 1em 20px !important;
}

Extra: Change the fields

This will change the background and border color of the highlighted fields & change the color of the label and the required text.

body .gform_wrapper li.gfield.gfield_error, body .gform_wrapper li.gfield.gfield_error.gfield_contains_required {
border-color: #65A9CC !important;
color: #444 !important;
background-color: #65A9CC !important; 
}

.gform_wrapper .gfield_error .gfield_label, .gform_wrapper .validation_message {
color: #FFFFFF !important;
}

And this will change the border for input fields to black (and not red):

.gform_wrapper li.gfield_error input[type="email"],
.gform_wrapper li.gfield_error input[type="number"],
.gform_wrapper li.gfield_error input[type="password"],
.gform_wrapper li.gfield_error input[type="tel"],
.gform_wrapper li.gfield_error input[type="text"],
.gform_wrapper li.gfield_error input[type="url"],
.gform_wrapper li.gfield_error textarea {
border: 1px solid #000;
}

Read more tutorials about Rocketgenius, Inc.

Rocketgenius builds advanced software solutions. Rocketgenius is the team behind Gravity Forms. Visit GravityForms.com
All tutorials Rocketgenius, Inc.