gform_form_args

Description

The filter gform_form_args provides the ability to modify the options used to display the form.

Usage

add_filter( 'gform_form_args', 'your_function_name' );

Parameters

  • $form_args array
    An array of arguments used to customize the embed method for the form being displayed.
    • form_id integer|string
      The ID or title of the form to be displayed.
    • display_title boolean
      Indicates if the form title should be displayed.
    • display_description boolean
      Indicates if the form description should be displayed.
    • force_display boolean
      Indicates if the form should be displayed even if it is set to inactive.
    • field_values array
      An array of dynamic population parameter keys with their corresponding values to be populated.
    • ajax boolean
      Indicates if the ifame-based legacy Ajax submission method is enabled.
    • tabindex integer
      0 or the starting tabindex to be used when generating the input markup.
    • submission_method null|string
      Since 2.9.0. Not set by default. The following are the possible string values when set, and the equivalent GFFormDisplay constants that can be used when setting the argument value:
      • postback or GFFormDisplay::SUBMISSION_METHOD_POSTBACK
        Indicates the form should use the default postback submission method.
      • iframe or GFFormDisplay::SUBMISSION_METHOD_IFRAME
        Indicates the form should use the iframe-based legacy Ajax submission method.
      • ajax or GFFormDisplay::SUBMISSION_METHOD_AJAX
        Indicates the form should use the new Ajax submission method introduced in 2.9.0, which uses a true Ajax request.
      • custom or GFFormDisplay::SUBMISSION_METHOD_CUSTOM
        Indicates the form should use a custom submission method. For example, payment add-ons that use custom JavaScript to communicate with the payment gateway before submitting the form will use this.

Examples

Configure title and description

add_filter( 'gform_form_args', 'setup_form_args' );
function setup_form_args( $form_args ) {
	$form_args['display_title']       = false;
	$form_args['display_description'] = true;

	return $form_args;
}

Enable new Ajax

The following would enable the new (true) Ajax submission method with Gravity Forms 2.9 and greater for all forms.

add_filter( 'gform_form_args', function ( $args ) {
	$args['submission_method'] = GFFormDisplay::SUBMISSION_METHOD_AJAX;

	return $args;
} );

The following approach shows how the new Ajax submission method could be enabled for specific forms.

add_filter( 'gform_form_args', function ( $args ) {
	if ( empty( $args['form_id'] ) || in_array( rgar( $args, 'submission_method' ), array( GFFormDisplay::SUBMISSION_METHOD_AJAX, GFFormDisplay::SUBMISSION_METHOD_CUSTOM ) ) ) {
		return $args;
	}

	$form_id = $args['form_id'];
	if ( ! is_numeric( $form_id ) ) {
		$form_id = GFFormsModel::get_form_id( $form_id );
		if ( $form_id === 0 ) {
			return $args;
		}
	}

	if ( ! in_array( $form_id, array( 1, 3 ) ) ) {
		return $args;
	}

	$args['submission_method'] = GFFormDisplay::SUBMISSION_METHOD_AJAX;

	return $args;
}, 90 );

Placement

This code should be placed in the functions.php file of your active theme.

Since

This filter was added in Gravity Forms 1.9.

Source Code

This filter is located in GFFormDisplay::get_form() in form_display.php.