Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save 13122310958/869111b85b844b0999328a9cb3073d59 to your computer and use it in GitHub Desktop.
Save 13122310958/869111b85b844b0999328a9cb3073d59 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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment