Run a php script after sending form
-
Hello,
I have an API that makes receipt, I need it to run after a form is completed and sent so that I can retrieve the informations of that form from the database, where can I put my php code so that it runs after sending the form ?
Thank you,
Mat.
-
Hi @matfr
I hope you are doing good today.
I pinged our Forminator Team and SLS Team to check which hook you could use to run your script after the form will be sent. For sure you will need to add it as a mu-plugin on your site. We will post an update here as soon as more information is available.
Kind Regards,
KrisHi @matfr
You can try this as a mu plugin with your custom script:
add_action( 'forminator_form_after_handle_submit', 'my_function' ); function my_function( $form_id, $response) { /* first check if $response['success'] and if so grab $form_id and continue with your code */ }Kind Regards,
KrisA small correction on the above snippet, it should be:
add_action( 'forminator_form_after_handle_submit', 'my_callback_function', 10, 2 );Hello,
I have put the code in a mu plugin but it doesn’t appear to work now ( my code works in a seperate php file so it’s not my code ), I have tried :
if ( ! defined( 'ABSPATH' ) ) { exit; } elseif ( defined( 'WP_CLI' ) && WP_CLI ) { return; } add_action('forminator_form_after_handle_submit','generation_proforma', 10, 2 ); function generation_proforma($form_id, $response) { if ($response['success']){ if ($form_id == 4323){ //my custom code }}else { }}Or do I need to fetch $form_id and $response in another way ?
Thanks !
-
This reply was modified 4 years, 2 months ago by
matfr.
I have also tried just :
if ( ! defined( 'ABSPATH' ) ) { exit; } elseif ( defined( 'WP_CLI' ) && WP_CLI ) { return; } add_action('forminator_form_after_handle_submit','generation_proforma', 10, 2 ); function generation_proforma($form_id, $response) { //my custom code }But that doesn’t work either… I have in my code 2 database querries that fetch the data of the form submitted, does this ‘forminator_form_after_handle_submit’ wait for the full data of the form to be sent to the database ?
Hello @matfr
Could you please share your custom code via a service like Pastebin so we better understand this? 🙂
Thank you,
DimitrisHello,
I would like to share my custom code with you no problem but not on the forum, is there a way I can send the code to you via e-mail or another way ?
Thank you,
Mat.
Hello @matfr !
No problem then, you can share the code (or better, a link to download on a cloud drive or https://pastebin.com) through our contact form:
https://wpmudev.com/contact/#i-have-a-different-question
Please use the template below:
Subject: “Attn: Pawel”
Message template:
– Download link to file on a cloud drive – Link back to this thread for reference (ex. https://wordpress.org/support/topic/ticket-title/) – Any other relevant URLs/infoTo ensure we don’t miss this please let us know here once you’ve submitted the form.
Kind regards,
PawelHello,
I sent the message through the contact form 🙂
-Mat
Hi @matfr
Thank you, I replied to it but also posting here.
I just tested the hook and it worked so the issue is related to a logic error, could you enable the debug mode https://wpmudev.com/blog/debugging-wordpress-how-to-use-wp_debug/ and see if any debug.log file will be generated after submission?
Best Regards
Patrick FreitasHi @matfr,
Since we haven’t heard from you for a while. I’ll mark this thread as resolved for now. Please feel free to re-open the thread if you need further assistance.
Best Regards
NithinHello,
I am currently in a mail exchange with Pawel,
He said he pinged the SLS team to look at my problem,
Waiting for a reply,
Regards.
My problem is solved,
A big thank you to Pawel and the SLS Team,
I needed to use :
add_action(‘forminator_form_after_save_entry’,”, 10, 2 );
Best Regards,
Mat.
-
This reply was modified 4 years, 2 months ago by
The topic ‘Run a php script after sending form’ is closed to new replies.