gform_entry_id_pre_save_lead

Description

Allows entry id to be changed before submission is saved. Useful to update an existing entry instead of creating a new one.

Usage

Apply to all forms.

add_filter( 'gform_entry_id_pre_save_lead', 'my_update_entry_on_form_submission', 10, 2 );

Apply to a specific form.

add_filter( 'gform_entry_id_pre_save_lead_10', 'my_update_entry_on_form_submission', 10, 2 );

Parameters

ParameterTypeDescription
$entry_idintegerDefault value is null.
$formForm ObjectThe current form.

Examples

Update an existing entry.

This example demonstrates how to use to this hook to retrieve an entry ID from the $_POST data and return it here so the existing entry is updated rather than a new entry created.

This assumes that the entry ID to be updated has been submitted with the form from an input which as the input name “my_update_entry_id”. You can store it in any input, but you will need to update the input name used when you retrieve the value via the rgpost() function.

add_filter( 'gform_entry_id_pre_save_lead', 'my_update_entry_on_form_submission', 10, 2 );
function my_update_entry_on_form_submission( $entry_id, $form ) {
	$update_entry_id = rgpost( 'my_update_entry_id' );
	return $update_entry_id ? $update_entry_id : $entry_id;
}

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

This filter is located in GFFormDisplay::handle_submission() in form_display.php.