The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
Delete from secondary table
Hello - new to extending Formidable but have found it to be very useful to be able to do so.
In my scenario, I have a few issues that make extending required:
- custom reporting requirements - i require data from multiple forms in a relational schema in order to build out reports in wpDataTables
- wpDataTables integration is incomplete without the ability to edit Formidable Forms
- regardless, I need custom views in wpDataTables that join multiple Formidable Forms - I attempted utilizing views that pivoted the data but because of the columnar storage of Formidable Forms, creating optimized views (even with limited data) is impossible and even simple joins time out
I have created secondary, optimized MySQL tables for each form. These are for reporting reasons only - I will be creating wpDataTables on top of these secondary tables for reporting purposes - I will not allow editing in these wpDataTables as that will cause data discrepancies between Formidable Forms and wpDataTables. I have the form entries inserting into my secondary table, I have the form updates updating my secondary table, but I cannot get the delete function to work. I believe this to be a simple fix but am spinning my wheels here.
add_action('frm_before_destroy_entry', 'delete_in_my_table', 20, 2);
function delete_in_my_table($entry_id){
$entry = FrmEntry::getOne($entry_id);
if ( $entry->form_id == 10 ) { // change 10 to your form id
global $wpdb;
$deleted_values = FrmEntryMeta::get_entry_meta_by_field($entry, 414, true);
//replace 414 with the field id from the Formidable form. Change enginemm_id to the column name in your table
$wpdb->delete('ct_enginemm', $deleted_values);
//change table_name to your table name
}
Any help would be greatly appreciated!
January 2, 2018 at 9:48 am
From a cursory perspective, it doesn't look like the syntax for your delete statement is correct. It should look like:
$wpdb->delete( $table, $where, $where_format = null )
https://codex.wordpress.org/Class_Reference/wpdb
January 2, 2018 at 10:49 am
I figured it would be easy - thank you! I think I was looking at the code too long.
I altered the code as listed below and it works as intended.
add_action('frm_before_destroy_entry', 'delete_in_my_table', 20, 2);
function delete_in_my_table($entry_id){
$entry = FrmEntry::getOne($entry_id);
if ( $entry->form_id == 10 ) { // change 10 to your form id
global $wpdb;
$deleted_values = array(
'enginemm_id' => FrmEntryMeta::get_entry_meta_by_field($entry, 414, true)
);//replace 414 with the field id from the Formidable form. Change enginemm_id to the column name in your table
$wpdb->delete('ct_enginemm', $deleted_values);
//change table_name to your table name
}
Discussion closed.