gform_update_meta()

Description

Updates the meta value of the specified meta key in the Entry Meta table. If the specified meta key does not exist, it will be created.

Usage

gform_update_meta( $entry_id, $meta_key, $meta_value );

Parameters

ParameterTypeDescription
$entry_idintegerThe ID of the entry.
$meta_keystringThe meta key of the meta value you wish to update.
$meta_valuestringThe value to be set as the new value for the specified meta key.
$form_idintegerThe form ID of the entry. This parameter is optional (including it removes the need to perform an extra query, if passed when creating the metadata). If it is not included, the $form_id parameter is set to null.

Examples

Store an API response in entry meta.

This example sets a meta value for the returned confirmation value from a call to a fictional API on post submission.

add_action( 'gform_after_submission', 'send_to_api' );
function send_to_api( $entry ) {

	// prepare entry details for third party API
	$lead_details = array( 'id' => $entry['id'], 'first_name' => $entry[1], 'last_name' => $entry[2] );

	// send to the third party API
	$response = process_lead( $lead_details );

	// add response value to entry meta
	gform_update_meta( $entry['id'], 'api_response', $response );

}

Source Code

This function is located in forms_model.php