The gform_submission_values_pre_save filter allows you to modify the submitted values before the incomplete submission is saved.
Usage
add_filter('gform_submission_values_pre_save', 'my_function_call');
Parameters
- $submitted_values (array): The submitted values.
- $form (array): The Form Object.
More information
See Gravity Forms Docs: gform_submission_values_pre_save
Examples
Modify a submitted value
In this example, we will modify a submitted value before saving the incomplete submission.
add_filter('gform_submission_values_pre_save', 'modify_submitted_value', 10, 2);
function modify_submitted_value($submitted_values, $form) {
// Modify submitted value
$submitted_values['field_id'] = 'New Value';
return $submitted_values;
}
Add a custom value to the submission
In this example, we will add a custom value to the submitted values before saving the incomplete submission.
add_filter('gform_submission_values_pre_save', 'add_custom_value', 10, 2);
function add_custom_value($submitted_values, $form) {
// Add a custom value to the submitted values
$submitted_values['custom_value'] = 'My Custom Value';
return $submitted_values;
}
Remove a value from the submission
In this example, we will remove a value from the submitted values before saving the incomplete submission.
add_filter('gform_submission_values_pre_save', 'remove_submitted_value', 10, 2);
function remove_submitted_value($submitted_values, $form) {
// Remove a value from the submitted values
unset($submitted_values['field_id']);
return $submitted_values;
}
Change submitted value based on the form ID
In this example, we will change a submitted value based on the form ID.
add_filter('gform_submission_values_pre_save', 'change_value_based_on_form', 10, 2);
function change_value_based_on_form($submitted_values, $form) {
// Check if the form ID is 5
if ($form['id'] == 5) {
// Modify submitted value
$submitted_values['field_id'] = 'Modified Value';
}
return $submitted_values;
}
Update a submitted value with user information
In this example, we will update a submitted value with the current user’s information.
add_filter('gform_submission_values_pre_save', 'update_value_with_user_info', 10, 2);
function update_value_with_user_info($submitted_values, $form) {
// Get the current user
$current_user = wp_get_current_user();
// Update the submitted value with the user's display name
$submitted_values['field_id'] = $current_user->display_name;
return $submitted_values;
}