Using Gravity Forms ‘gform_incomplete_submission_pre_save’ PHP action

The gform_incomplete_submission_pre_save filter allows you to override the draft submission for Save and Continue before it’s saved to the database.

Usage

add_filter('gform_incomplete_submission_pre_save', 'your_function_name', 10, 3);

Parameters

  • $submission_json (array) – JSON encoded associative array containing the incomplete submission. The array includes submitted values, draft entry created from the submitted values, dynamic population field values, form’s current page number, uploaded file properties, and the unique ID for this submission.
  • $resume_token (string) – The unique token which can be used to resume the incomplete submission at a later date/time.
  • $form (Form Object) – The form object.

More information

See Gravity Forms Docs: gform_incomplete_submission_pre_save

Examples

Modify the user’s first name in the saved data

add_filter('gform_incomplete_submission_pre_save', 'modify_incomplete_submission', 10, 3);

function modify_incomplete_submission($submission_json, $resume_token, $form) {
    // Change the user first name to Test in the saved data
    $updated_json = json_decode($submission_json);
    $updated_json->submitted_values->{'1'}->{'1.3'} = 'Test';
    $submission_json = json_encode($updated_json);

    return $submission_json;
}

Place this code in the functions.php file of your active theme. This example modifies the user’s first name in the saved data to “Test” before the submission is saved to the database.

Add a custom note to the saved data

add_filter('gform_incomplete_submission_pre_save', 'add_custom_note', 10, 3);

function add_custom_note($submission_json, $resume_token, $form) {
    // Add a custom note to the saved data
    $updated_json = json_decode($submission_json);
    $updated_json->submitted_values->{'custom_note'} = 'This is a custom note.';
    $submission_json = json_encode($updated_json);

    return $submission_json;
}

This example adds a custom note to the saved data before the submission is saved to the database.

Remove a specific field from the saved data

add_filter('gform_incomplete_submission_pre_save', 'remove_specific_field', 10, 3);

function remove_specific_field($submission_json, $resume_token, $form) {
    // Remove field with ID 5 from the saved data
    $updated_json = json_decode($submission_json);
    unset($updated_json->submitted_values->{'5'});
    $submission_json = json_encode($updated_json);

    return $submission_json;
}

This example removes a specific field with ID 5 from the saved data before the submission is saved to the database.

Add a timestamp to the saved data

add_filter('gform_incomplete_submission_pre_save', 'add_timestamp', 10, 3);

function add_timestamp($submission_json, $resume_token, $form) {
    // Add a timestamp to the saved data
    $updated_json = json_decode($submission_json);
    $updated_json->submitted_values->{'timestamp'} = time();
    $submission_json = json_encode($updated_json);

    return $submission_json;
}

This example adds a timestamp to the saved data before the submission is saved to the database.