Clearer Gravity Forms Error Summary
Replaces the error message at the top of a Gravity Forms form with your own wording and lists how many fields need attention, announced to screen readers.
Opens WPIDE on
Code
$wpide_gf_error_text = 'Almost there! Please fix the %d highlighted field(s) below.';
add_filter( 'gform_validation_message', function ( $message, $form ) use ( $wpide_gf_error_text ) {
$count = 0;
foreach ( $form['fields'] as $field ) {
if ( ! empty( $field->failed_validation ) ) {
$count++;
}
}
return sprintf( '<div class="gform_validation_errors validation_error" role="alert"><h2 class="gform_submission_error">%s</h2></div>', esc_html( sprintf( $wpide_gf_error_text, max( 1, $count ) ) ) );
}, 10, 2 );
Notes
Edit the sentence at the top; %d is replaced with the number of fields that need fixing.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.