Form_delete_entry

I’m storing GF data in a separate database “CWRoles”
I’ve got it all working fine as far as adding new entries is concerned. Now trying to ensure that when an entry is deleted the CWRoles is updated by deleting the same entry in that table.

Not sure if the function can also be limited to a specific form (7) by using : add_action( ‘gform_delete_entry_7’, ‘delete_entry’, 10, 2 ) as you can other functions.

Would be grateful for any advice.

Thanks

Code below not working:

add_action( 'gform_delete_entry’, ‘delete_entry', 10, 2 );
function delete_entry($entry_id, $form) {
global $wpdb;
$tablename = "CWRoles";
$Rentryid = $entry_id;
$SQL="DELETE FROM $tablename WHERE cwrentryid = $Rentryid;";
$wpdb->query($SQL);

}

That cannot be limited to a form by adding the _7 as you were asking.

As in your other topic, I recommend adding some additional logging statements, so you can figure out what is not working the way you planned it. There’s no need to try and do this blind. Add lots of logging statements and enable the Gravity Forms built in logging, and see what shows up. Let us know what you find out.

While it is true you can’t append a form ID to the hook name to target a specific form ID, you do have access to the entry ID which you can use to get the full entry object which contains the form ID, you can then run conditionals based on that:

add_action( 'gform_delete_entry', 'delete_entry_post' );
function delete_entry_post( $entry_id ) {
	GFCommon::log_debug( __METHOD__ . '(): running.' );
	// Getting entry object.
	$entry = GFAPI::get_entry( $entry_id );
	$form_id = rgar( $entry, 'form_id' );

	if ( $form_id == 7 ) {

		GFCommon::log_debug( __METHOD__ . '(): running for form ID ' . $form_id );
		
		// do your code here for when an entry is deleted from form #7
		
	}
}
1 Like

Hi
Have updated my code:

add_action( 'gform_delete_entry’, ‘delete_cwrentry', 10,1);
function delete_cwrentry($entry_id) {
	GFCommon::log_debug( __METHOD__ . '(): running.' );
	// Getting entry object.
	$entry = GFAPI::get_entry( $entry_id );
	// identify the form number
	$form_id = rgar( $entry, 'form_id' );
	//if form is 7 then delete entry with same entry id from CWRoles 
	if ( $form_id == 7 ) {

		GFCommon::log_debug( __METHOD__ . '(): running for form ID ' . $form_id );
	
global $wpdb;
$tablename = "CWRoles";
$Rentryid = $entry;
$SQL="DELETE FROM $tablename WHERE cwrentryid= '".$Rentryid."'";
$wpdb->query($SQL);

}
}

The GF log on this is shown below. This shows only that the deletion of the entry on form 7 is taking place in the GF entries. However, I can’t see the triggering of the hook ‘gform_delete_entry’. Although I am clearly deleting an entry on form 7 Something is resulting in the hook not triggering. (Note I have replaced the long code appearing within the log with [Long Code] ). Perhaps I need to be more specific with the table name to include the full path? if its not finding “CWRoles”

GF Log:

2021-10-31 16:04:15.406744 - DEBUG --> GFFormsModel::delete_entry(): User ID 1 requested deletion of entry #369 
2021-10-31 16:04:15.406877 - DEBUG --> GFFormsModel::delete_entry(): Deleting entry #369. 
2021-10-31 16:04:16.963910 - DEBUG --> GF_Query::query(): sql => SELECT SQL_CALC_FOUND_ROWS DISTINCT `t1`.`id` FROM `wp_15_gf_entry` AS `t1` LEFT JOIN `wp_15_gf_entry_meta` AS `m3` ON `m3`.`entry_id` = `t1`.`id` LEFT JOIN `wp_15_gf_entry_meta` AS `o2` ON (`o2`.`entry_id` = `t1`.`id` AND `o2`.`meta_key` = 1) WHERE (`t1`.`form_id` IN (7) AND (`t1`.`status` = 'active' AND `m3`.`meta_value` LIKE '{[Long  Code]}{[Long Code]}')) ORDER BY `o2`.`meta_value` ASC LIMIT 10 
2021-10-31 16:04:16.979068 - DEBUG --> GF_Query::query(): sql => SELECT SQL_CALC_FOUND_ROWS DISTINCT `t1`.`id` FROM `wp_15_gf_entry` AS `t1` WHERE (`t1`.`form_id` IN (7) AND `t1`.`status` = 'active') ORDER BY `t1`.`id` DESC LIMIT 20 
2021-10-31 16:04:16.980643 - DEBUG --> GF_Query::query(): sql => SELECT SQL_CALC_FOUND_ROWS DISTINCT `t1`.`id` FROM `wp_15_gf_entry` AS `t1` LEFT JOIN `wp_15_gf_entry_meta` AS `m2` ON `m2`.`entry_id` = `t1`.`id` WHERE (`t1`.`form_id` IN (7) AND (`t1`.`status` = 'active' AND `m2`.`meta_value` LIKE '{[Long Code]}{[Long Code]}')) ORDER BY `t1`.`id` DESC LIMIT 20

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.