gform_get_form_filter

Override the HTML output of any Gravity Form, after it is generated – but BEFORE it is displayed.

Start using gform_get_form_filter

What gform_get_form_filter does…

Using this – you can change the appearance or display of any Gravity Form.

Want to target all forms?

Use this:

add_filter( 'gform_get_form_filter', 'your_function_name', 10, 2 );

Want to target a specific form?

Use this:

add_filter( 'gform_get_form_filter_10', 'your_function_name', 10, 2 );

[…spot the difference? you add the form number to the end of the gform_get_form_filter_ tag]

What parameters does this filter use?

  • $form_string string
    • [controlling form markup HTML]
  • $form Form Object
    • [identifying the form]

Use Case Examples?

Want to hide a Gravity Form for logged-in users?

Example:

add_filter( 'gform_get_form_filter_1', function ( $form_string, $form ) {
if ( is_user_logged_in() ) {
$form_string = "

This form is for new users, as you are already registered you don't need to use it again.

";
}

return $form_string;
}, 10, 2 );

Want to hide a Gravity Form from displaying on a specific day of the week?

Example:

add_filter( 'gform_get_form_filter_1', 'custom_schedule', 10, 2 );
function custom_schedule( $form_string, $form ) {
$day = date( 'l' );
if ( $day == 'Monday' ) {
$form_string = '

We are closed today, please return tomorrow to make your booking.

';
}

return $form_string;
}

Want to remove a specific CSS form class from a particular Gravity Form?

Example:

add_filter( 'gform_get_form_filter_63', function ( $form_string, $form ) {
// Remove gf_simple_horizontal if page ID is not 9098.
if ( ! is_page( 9098 ) ) {
$form_string = str_replace( 'gf_simple_horizontal', '', $form_string );
}

return $form_string;
}, 10, 2 );

Where should you place this code in your WordPress website?

In the functions.php file of your active theme.

Was this article helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *