Using Gravity Forms ‘gform_post_add_entry’ PHP action

The gform_post_add_entry Gravity Forms action fires after an entry has been added via the GFAPI::add_entry() function.

Usage

add_action('gform_post_add_entry', 'your_function_name', 10, 2);

Parameters

  • $entry (Entry Object): The entry after being added.
  • $form (Form Object): The form object.

More information

See Gravity Forms Docs: gform_post_add_entry

This action is located in GFAPI::add_entry() in includes/api.php.

Examples

Log Entry Data

Logs the entry data after it has been added.

function log_post_add_entry($entry, $form) {
    GFCommon::log_debug('gform_post_add_entry: entry => ' . print_r($entry, 1));
}
add_action('gform_post_add_entry', 'log_post_add_entry', 10, 2);

Send Email Notification

Sends a custom email notification when a new entry is added.

function send_email_on_new_entry($entry, $form) {
    // Replace with your email address
    $to = "[email protected]";
    $subject = "New Form Entry Received";
    $message = "A new entry has been added. Here are the details:\n\n";
    $message .= print_r($entry, 1);

    wp_mail($to, $subject, $message);
}
add_action('gform_post_add_entry', 'send_email_on_new_entry', 10, 2);

Add Entry to Custom Database Table

Inserts the entry data into a custom database table.

function insert_entry_to_custom_table($entry, $form) {
    global $wpdb;
    $table_name = $wpdb->prefix . "custom_table";

    $data = array(
        'entry_id' => $entry['id'],
        'form_id' => $form['id'],
        'created_at' => $entry['date_created'],
    );

    $wpdb->insert($table_name, $data);
}
add_action('gform_post_add_entry', 'insert_entry_to_custom_table', 10, 2);

Redirect to Custom Thank You Page

Redirects the user to a custom thank you page after the entry has been added.

function redirect_to_custom_thank_you_page($entry, $form) {
    $thank_you_url = "https://example.com/thank-you";
    wp_redirect($thank_you_url);
    exit;
}
add_action('gform_post_add_entry', 'redirect_to_custom_thank_you_page', 10, 2);

Update User Meta

Updates user meta data based on the entry data.

function update_user_meta_on_entry($entry, $form) {
    // Replace 1 with your field ID
    $user_id = rgar($entry, '1');

    // Replace 2 with your field ID
    $new_value = rgar($entry, '2');

    update_user_meta($user_id, 'custom_meta_key', $new_value);
}
add_action('gform_post_add_entry', 'update_user_meta_on_entry', 10, 2);