PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Delete lead on another forms submission

  1. 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 );
    
        	}
        }
    
    }
    Posted 9 years ago on Wednesday October 3, 2012 | Permalink
  2. Been playing with this for a few hours now. Still nothing. I have tried gform_post_submission as well. The form still gets caught up. If I dont have the foreach loop it will delete the entry that was just pushed through, but I need to find the entry within another form...

    Any thoughts?

    Posted 9 years ago on Wednesday October 3, 2012 | Permalink
  3. gform_post_submission is deprecated. Use gform_after_submission now. Usage is identical.

    Posted 9 years ago on Wednesday October 3, 2012 | Permalink