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_idinteger|string
The ID or title of the form to be displayed.display_titleboolean
Indicates if the form title should be displayed.display_descriptionboolean
Indicates if the form description should be displayed.force_displayboolean
Indicates if the form should be displayed even if it is set to inactive.field_valuesarray
An array of dynamic population parameter keys with their corresponding values to be populated.ajaxboolean
Indicates if the ifame-based legacy Ajax submission method is enabled.tabindexinteger0or the starting tabindex to be used when generating the input markup.submission_methodnull|string
Since 2.9.0. Not set by default. The following are the possible string values when set, and the equivalentGFFormDisplayconstants that can be used when setting the argument value:postback(GFFormDisplay::SUBMISSION_METHOD_POSTBACK)
Indicates the form should use the default postback submission method.iframe(GFFormDisplay::SUBMISSION_METHOD_IFRAME)
Indicates the form should use the iframe-based legacy Ajax submission method.ajax(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. Some add-ons don’t currently support the new Ajax submission method, so you should only enable this feature on production sites for forms where you have fully tested it.
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 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'] ) || rgar( $args, 'submission_method' ) === GFFormDisplay::SUBMISSION_METHOD_AJAX ) {
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.