Title: Run custom code when form submit
Last modified: February 16, 2025

---

# Run custom code when form submit

 *  Resolved [vi54](https://wordpress.org/support/users/vi54/)
 * (@vi54)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/run-custom-code-when-form-submit/)
 * Hello there, using the free version.
   How can I create a hook to send a custom
   email? The idea is that I can control some of the values, calculate numbers and
   so on, before i send.Yes I can use the calculation items inside of the plugin,
   but eventually the code will have to check versus arrays and build replies based
   on the calculations. Calculations in the plugin are limited.Whatever I try and
   google, nothing works, so I ask here.1. The hook must be able to grab data from
   the email that is submitted.2. I will have to perform my calculations.3. The 
   hook must be able to send to the customer a specific email with some info.4. 
   The hook must send the submitted info to the adminI have found this, but it does
   not work.
 *     ```wp-block-code
       add_action( 'forminator_form_after_save_entry', 'my_form_submit', 10, 2 ); function my_form_submit( $form_id, $response ) {     if ( $response && is_array( $response ) ) {         if ( $response['success'] ) {             if ( $form_id == 6 ) { 		// Code goes in here            }         }     } }
       ```
   
 * I had transformed it into —
 *     ```wp-block-code
       add_action('forminator_form_after_save_entry', 'function_Name', 10, 2);function function_Name($form_id, $response){if (isset($response['success']) && $response['success']) {// Log the form submission dataerror_log('Form submission data: ' . print_r($response, true));    // Test wp_mail function    test_wp_mail(); // Make sure this is your function to test sending emails}}// A basic test wp_mail function to ensure it's workingfunction test_wp_mail(){$to = 'myemail@mydomain.com'; // Updated email for testing$subject = 'Test email from wp_mail';$message = 'This is a test email to check if wp_mail is working.';$headers = array('Content-Type: text/plain; charset=UTF-8');$mail_sent = wp_mail($to, $subject, $message, $headers);// Log the result of wp_mailif ($mail_sent) {    error_log('Test email sent successfully!');} else {    error_log('Test email failed to send.');}}
       ```
   
 * 
   Thanks for your help!
    -  This topic was modified 1 year, 3 months ago by [vi54](https://wordpress.org/support/users/vi54/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Support [Amin – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support2/)
 * (@wpmudev-support2)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/run-custom-code-when-form-submit/#post-18309013)
 * Hello [@vi54](https://wordpress.org/support/users/vi54/)
 * Hope you are doing well today.
 * If you want to edit the form email you can use **forminator_custom_form_mail_before_send_mail**
   hook, and if you want to send a different custom email you should look for **
   send_email **function in this file /forminator/library/modules/custom-forms/front/
   front-action.php file.
 * Since custom coding is out of scope of our support if you need further assistance,
   you’ll need to hire a developer to provide the required custom code for you. 
   WordPress provides a jobs directory here [https://jobs.wordpress.net/](https://jobs.wordpress.net/),
   if you need further advice about it, feel free to email `wpsupport@incsub.com`.
 * Subject: ATTN: WPMU DEV support – wp.org
 * Kind Regards
    Amin
 *  Thread Starter [vi54](https://wordpress.org/support/users/vi54/)
 * (@vi54)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/run-custom-code-when-form-submit/#post-18309155)
 * That is perfect Amin!
   Amazing that I did not spot that ook!It works perfectly.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Run custom code when form submit’ is closed to new replies.

 * ![](https://ps.w.org/forminator/assets/icon-256x256.gif?rev=3443182)
 * [Forminator Forms – Contact Form, Payment Form & Custom Form Builder](https://wordpress.org/plugins/forminator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/forminator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/forminator/)
 * [Active Topics](https://wordpress.org/support/plugin/forminator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/forminator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/forminator/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [vi54](https://wordpress.org/support/users/vi54/)
 * Last activity: [1 year, 3 months ago](https://wordpress.org/support/topic/run-custom-code-when-form-submit/#post-18309155)
 * Status: resolved