Vai al contenuto
Home 01 Clienti 02 Chi siamo 03 Blog 04 Contatti 05
ITENHR
Home / Gravity Forms Tips – Aggiorna valore di un campo dopo Aggiornamento
Gravity Forms

Gravity Forms Tips – Aggiorna valore di un campo dopo Aggiornamento

29 Settembre 2020 Aggiornato il 17 Settembre 2020

Questa funzione di Gravity forms permette di aggiornare un valore dei un campo dopo l’aggiornamento del modulo

Può essere utile per un aggiornamento di un valore predefinito o impostare un contattore per il numero di volte che un modulo è stato aggiornato

Ecco la funzione da inserire nel file function.php del proprio tema di wordpress


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 );