bookmark_borderDelete Entry Data after Submission

By default, Gravity Forms was designed to record all data submitted to it, so there isn’t an override to stop Gravity Forms from storing entry data upon submission.

Here are some third-party add-ons which add the ability to delete entries either as the form submission ends or at a scheduled date/time:

If you would prefer not to use one of the above add-ons you can use custom code in the theme functions.php file or a custom functionality plugin that will wait until the data is recorded, and then go in and remove the entry that was just created. The reason for this is the entry must be saved so the data is available when notifications are sent and feed based add-ons, like PayPal and User Registration, are processed. To do so, you would use the following code which works with Gravity Forms 1.8 and newer:

// Target submissions from form ID  1.
// Change gform_after_submission_1 to reflect your target form ID, or use gform_after_submission to target all forms.
add_action( 'gform_after_submission_1', 'remove_form_entry' );
function remove_form_entry( $entry ) {
    GFAPI::delete_entry( $entry['id'] );
}

The following code is applicable to Gravity Forms 1.7 and earlier only.

add_action('gform_after_submission_1', 'remove_form_entry', 10, 2);
function remove_form_entry($entry, $form){
    global $wpdb;

    $lead_id = $entry['id'];
    $lead_table = RGFormsModel::get_lead_table_name();
    $lead_notes_table = RGFormsModel::get_lead_notes_table_name();
    $lead_detail_table = RGFormsModel::get_lead_details_table_name();
    $lead_detail_long_table = RGFormsModel::get_lead_details_long_table_name();

    //Delete from detail long
    $sql = $wpdb->prepare(" DELETE FROM $lead_detail_long_table
                            WHERE lead_detail_id IN(
                                SELECT id FROM $lead_detail_table WHERE lead_id=%d
                            )", $lead_id);
    $wpdb->query($sql);

    //Delete from lead details
    $sql = $wpdb->prepare("DELETE FROM $lead_detail_table WHERE lead_id=%d", $lead_id);
    $wpdb->query($sql);

    //Delete from lead notes
    $sql = $wpdb->prepare("DELETE FROM $lead_notes_table WHERE lead_id=%d", $lead_id);
    $wpdb->query($sql);

    //Delete from lead
    $sql = $wpdb->prepare("DELETE FROM $lead_table WHERE id=%d", $lead_id);
    $wpdb->query($sql);

}

The expected behavior would be that the entry would not exist in the Gravity Forms database tables after submission. If you are having issues with this script, please read up on our gform_after_submission hook.