Using Gravity Forms ‘gform_post_note_added’ PHP action

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.

More information

See Gravity Forms Docs: gform_post_note_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.

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;
    }
    GFCommon::log_debug("gform_post_note_added: Draft entry based on values for failed entry (#{$entry_id}) => " . print_r(GFFormsModel::get_current_lead(), 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.

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