Using Gravity Forms ‘gform_form_settings_before_save’ PHP filter

The gform_form_settings_before_save filter in Gravity Forms allows you to modify the form object before it’s saved on the Form Settings page. This is particularly handy when you need to save custom settings that were added via the gform_form_settings filter.

Usage

Here’s a simple way to use the filter:

add_filter("gform_form_settings_before_save", "my_custom_function");

In this example, replace my_custom_function with your custom function that processes the form data.

Parameters

  • $form (Form Object): The current form object being edited.

More information

See Gravity Forms Docs: gform_form_settings_before_save
Remember to check for the latest updates and information about this filter on the official documentation page.

Examples

Modifying a form field before saving

This example demonstrates how to modify a form field before it’s saved. We are changing the title of the form field with the ID ‘2’.

function change_field_title_before_save( $form ) {
    // your custom code here
    $form['fields'][2]['label'] = 'New Title';
    return $form;
}
add_filter('gform_form_settings_before_save', 'change_field_title_before_save');

Adding a custom setting

In this example, we’re adding a custom setting to the form object before it’s saved.

function add_custom_setting( $form ) {
    // your custom code here
    $form['customSetting'] = 'Custom Value';
    return $form;
}
add_filter('gform_form_settings_before_save', 'add_custom_setting');

Removing a form field

This example demonstrates how to remove a form field before saving the form settings.

function remove_form_field( $form ) {
    // your custom code here
    unset($form['fields'][2]);
    return $form;
}
add_filter('gform_form_settings_before_save', 'remove_form_field');

Changing form properties

This example changes the title and description of the form before it’s saved.

function modify_form_properties( $form ) {
    // your custom code here
    $form['title'] = 'New Form Title';
    $form['description'] = 'New Form Description';
    return $form;
}
add_filter('gform_form_settings_before_save', 'modify_form_properties');

Modifying form confirmation settings

This example shows how to modify the form confirmation settings before saving the form.

function modify_form_confirmation( $form ) {
    // your custom code here
    $form['confirmations']['default']['message'] = 'Thanks for your submission!';
    return $form;
}
add_filter('gform_form_settings_before_save', 'modify_form_confirmation');