issue with the frm_after_create_entry hook

By: David TABARY | Asked: 12/30/2022
ForumsCategory: Code Helpissue with the frm_after_create_entry hook
David TABARY asked 2 years ago
Hi, I'm using this hook to insert the data of one of my forms in another table of my database : https://formidableforms.com/knowledgebase/frm_after_create_entry/#kb-insert-form-data-into-second-database-table I use the WP Code plugin to insert the hook on the page where the form is located. But everytime I activate the snippet, it gets deactivated and WP Code tells me : Snippet not activated, the following error was encountered: syntax error, unexpected token "=", expecting ")"   Any idea of what could go wrong ?   Here is the hook : add_action('frm_after_create_entry', 'copy_into_my_table', 30, 2);
function copy_into_my_table($entry_id, $form_id){
if($form_id == 17){
global $wpdb;
$values = array('title' => $_POST['item_meta'][513],
'user' => $_POST['item_meta'][517],
'OT' => $_POST['item_meta'][518],
'comptoir' => $_POST['item_meta'][523],
'date' => $_POST['item_meta'][527],
'year' => $_POST['item_meta'][528],
'mois' => $_POST['item_meta'][530],
'jour' => $_POST['item_meta'][532],
'heure' => $_POST['item_meta'][531],
'mode_sollicitation' => $_POST['item_meta'][533],
'tags_principaux' => $_POST['item_meta'][535],
'tags_autre' => $_POST['item_meta'][537],
'tags_territoire' => $_POST['item_meta'][539],
'autre_demande_territoire' => $_POST['item_meta'][540],
'nb_passcuriste' => $_POST['item_meta'][541],
'nationalite' => $_POST['item_meta'][542],
'region' => $_POST['item_meta'][547],
'departement' => $_POST['item_meta'][546],
'commune' => $_POST['item_meta'][545],
'mel' => $_POST['item_meta'][548],
'hdf' => $_POST['item_meta'][549],
'budget_hebergement' => $_POST['item_meta'][573]);
$wpdb->insert('wp_sollicit', $values);
}
}
1 Answers
Victor Font answered 2 years ago

I've reviewed your code and find no errors. The problem you're experiencing is probably not originating with this code. The code is written correctly and does not produce errors when run through a PHP Lint checker for PHP versions 7.4 and 8.2. This code should work for all PHP versions from 7.4 and later. This means that either the WP Code plugin or your data is at fault, if its execution gets far enough to actually parse $_POST. I'm not familiar with WP Code. I would try the Code Snippets plugin, which is what I use, or adding the code directly to functions.php. Code Snippets flags syntax errors as you type. If it still produces errors, you'll need to enable WordPress debug to try to isolate a line number for the error. The 'syntax error, unexpected token "=", expecting ")"' tells us that WP Code is detecting something wrong but is not identifying where as in which line. Have you opened a support ticket with the WP Code developers?

David TABARY replied 2 years ago

Thank you for your help. I opened a ticket at WP Code, I'm waiting for their answer. But it seems that even directly in functions.php, not all entries get copied in the other database table. There must be something wrong somewhere. I'm gonna try to turn the debug mode on and see what happens.

David TABARY replied 2 years ago

It gets me this, not sure to understand :
[30-Dec-2022 12:52:07 UTC] PHP Fatal error: Cannot redeclare copy_into_my_table() (previously declared in /home/u140737336/domains/team-ot.net/public_html/wp-content/plugins/wpcode-premium/includes/class-wpcode-snippet-execute.php(268) : eval()'d code:2) in /home/u140737336/domains/team-ot.net/public_html/wp-content/plugins/wpcode-premium/includes/class-wpcode-snippet-execute.php(268) : eval()'d code on line 2

Victor Font replied 2 years ago

You're getting this because the snippet is still active in WP Code. Functions can only be declared 1 time in a system. It was declared in WP Code before functions.php loaded.

David TABARY replied 2 years ago

My last message wasn't clear but I got this in the log before to put the code in the functions.php file, so there's really something wrong with the WP Code plugin. Since the moment I deactivated WP Code and placed my snippet directly in functions.php everything is going fine. I had a problem with some entries not being posted to the database but I discovered it was the fault of a field in my form. Now everything works like it should. Thanks for your help Victor.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right