Description
The “gform_post_note_added” action is triggered after a note is added to an entry in Gravity Forms, allowing further actions to be performed.
Usage
add_action( 'gform_post_note_added' , 'your_function_name' , 10, 7 ); |
Parameters
- $note_id integer
The ID assigned to the note by the database. - $entry_id integer
The ID of the entry the note was added to. - $user_id integer
Zero or the ID of the user who added the note. - $user_name string
The name of the plugin or the user_name of the user who added the note. - $note string
The note that was added. - $note_type string
The type of the note that was added. - $sub_type string
The subtype of the note that was added.
Examples
Log failed entry
Occasionally, a database error can occur when saving the field values for an entry. This code snippet can be used to create a draft entry from the submitted values and write it to the core log.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | add_action( 'gform_post_note_added' , function ( $note_id , $entry_id , $user_id , $user_name , $note , $note_type , $sub_type ) { if ( $note_type !== 'save_entry' || $sub_type !== 'error' ) { return ; } $entry = GFFormsModel::get_current_lead(); $log_entry = json_encode( $entry , JSON_INVALID_UTF8_SUBSTITUTE ); if ( ! $log_entry ) { $log_entry = $entry ; } GFCommon::log_debug( "gform_post_note_added: Draft entry based on values for failed entry (#{$entry_id}) => " . print_r( $log_entry , true ) ); global $wpdb ; GFCommon::log_debug( 'gform_post_note_added: gf_entry_meta meta_value charset = ' . print_r( $wpdb ->get_col_charset( GFFormsModel::get_entry_meta_table_name(), 'meta_value' ), true ) ); }, 10, 7 ); |
Send notifications configured for the custom event note_added
The following example assumes you have already added a custom notification event with the filter gform_notification_events defined as ‘note_added’. It will check if there’s any active notification configured for that event, and process them if any.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | add_action( 'gform_post_note_added' , 'send_note_added_notifications' , 10, 2 ); function send_note_added_notifications( $insert_id , $entry_id ) { GFCommon::log_debug( __METHOD__ . "(): Running for entry id {$entry_id}" ); $entry = GFAPI::get_entry( $entry_id ); $form_id = rgar( $entry , 'form_id' ); $form = GFAPI::get_form( $form_id ); // Replace note_added with the name you have used to define your event $event = 'note_added' ; $notifications_to_send = GFCommon::get_notifications_to_send( $event , $form , $entry ); $log_notification_event = empty ( $notifications_to_send ) ? 'No notifications to process' : 'Processing notifications' ; GFCommon::log_debug( "gform_post_note_added: {$log_notification_event} for {$event} event." ); if ( ! empty ( $notifications_to_send ) ) { GFAPI::send_notifications( $form , $entry , $event ); } } |
Source Code
This action hook is located in forms_model.php.