I am trying to use a form with the form ID 2 that has a dropdown option of restaurants along with an email input field. The user can choose the restaurant they were going to attend, enter their email address and then when submitted it will find their entry that matches the restaurant & email from form ID 1 and delete it.
I am using this, but the submission of the form never goes through, nor does it delete anyone...
// Form ID 2
add_action("gform_after_submission_2", "gf_remove_rsvp_entry", 10, 2);
function gf_remove_rsvp_entry($entry, $form){
$email = $_POST["input_1"];
$restaurant = $_POST["input_2"];
//Reading entries from our RSVP Form ID 1;
$entries = RGFormsModel::get_leads(1, '', 'DESC', '', '0', '99999999');
foreach($entries as $entry){
if($email == $entry["4"] && $restaurant == $entry["9"]){
// Get our Leads
$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 );
}
}
}