Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save zackkatz/7f8d926e5d9fad23b53783e4a26be55f to your computer and use it in GitHub Desktop.
Save zackkatz/7f8d926e5d9fad23b53783e4a26be55f to your computer and use it in GitHub Desktop.
Gravity Forms - Modify field value after updating in Gravity Forms OR GravityView
<?php
/**
* Modify a field value after updating an entry
*
* @param array $form Gravity Forms form object
* @param int $entry_id ID of the entry that was updated
* @param array $original_entry Original entry object, before update
*
* @return void
*/
function gv_custom_gform_after_update_entry( $form = array(), $entry_id = 0, $original_entry = array() ) {
// Get the current entry
$updated_entry = GFAPI::get_entry( $entry_id );
// Set a new value for Field #5
$field_id_or_meta_key_to_edit = '5';
// Define the new value here
$new_value = 'New Value';
$updated_entry[ $field_id_or_meta_key_to_edit ] = $new_value;
// Save the update
$updated = GFAPI::update_entry( $updated_entry );
if ( ! $updated ) {
gf_logging()->log_error( __FUNCTION__ . ': Entry failed to update' );
} elseif ( is_wp_error( $updated ) ) {
gf_logging()->log_error( __FUNCTION__ . ': Entry failed to update: ' . $updated->get_error_message() );
}
}
add_action( 'gform_after_update_entry', 'gv_custom_gform_after_update_entry', 10, 3 );
@richardpbull
Copy link

Thank you for posting this. Very useful for keeping gravity forms and a database in sync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment