The gform_post_process action fires after the form processing is completed, allowing further actions to be performed. It can be used on a single-page form or when navigating between pages on a multi-page form.
Usage
add_action('gform_post_process', 'your_function_name', 10, 3);
For a specific form, use the format gform_post_process_FORMID
:
add_action('gform_post_process_1', 'your_function_name', 10, 3);
Parameters
- $form (Form Object): The form object.
- $page_number (int): In a multi-page form, this variable contains the current page number.
- $source_page_number (int): In a multi-page form, this parameter contains the number of the page from which the submission came.
More information
See Gravity Forms Docs: gform_post_process
Examples
Display a message based on field value
In this example, we’ll display a message if the value of field 1 is “Contact”:
add_action('gform_post_process', 'post_process_actions', 10, 3); function post_process_actions($form, $page_number, $source_page_number) { // Get the value of field 1 $field_1_value = rgpost('input_1'); // Display message if value is "Contact" if ($field_1_value == 'Contact') { echo 'Form submitted with Contact as value in field 1'; } }
Redirect to a different page based on field value
This example shows how to redirect the user to different pages based on the value of a field:
add_action('gform_post_process', 'redirect_based_on_field', 10, 3); function redirect_based_on_field($form, $page_number, $source_page_number) { // Get the value of field 1 $field_1_value = rgpost('input_1'); // Redirect based on field 1 value if ($field_1_value == 'Option1') { wp_redirect('https://example.com/option1'); exit; } elseif ($field_1_value == 'Option2') { wp_redirect('https://example.com/option2'); exit; } }
Save submitted data to a custom database table
This example demonstrates how to save submitted form data to a custom database table:
add_action('gform_post_process', 'save_to_custom_table', 10, 3); function save_to_custom_table($form, $page_number, $source_page_number) { global $wpdb; // Get the value of field 1 $field_1_value = rgpost('input_1'); // Insert data into custom table $wpdb->insert( 'your_custom_table', array( 'field_1_value' => $field_1_value ) ); }