The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
|
Emails not sent from API (Using AJAX) **FIXED** - Printable Version +- Form Tools (https://forums.formtools.org) +-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1) +--- Forum: API (https://forums.formtools.org/forumdisplay.php?fid=17) +--- Thread: Emails not sent from API (Using AJAX) **FIXED** (/showthread.php?tid=2365) |
Emails not sent from API (Using AJAX) **FIXED** - designguy - Feb 1st, 2013 Ive had a lot of hassle setting up Formtools to run from an Ajax call, sorted out most issues and can now get my page to send the formdata via AJAX to a php file which will submit the data to fromtools and return JSON if success or failure. Important to note I DO NOT have a thank you page, A Modal box is displayed using Javascript on a successful ajax call. However emails are not being sent. Ive set them up, Have on submission set as the trigger.... * Sending test emails works ok * Form data being saved * No emails being sent on submission code excluding validation code $_POST['submit'] = 'submit'; // no submit button in ajax form $form_id = @$_REQUEST['form_tools_form_id']; $fields = ft_api_init_form_page($form_id); $params = array( "submit_button" => "submit", "next_page" => "", "form_data" => $_POST, "file_data" => $_FILES, "finalize" => true, "send_emails" => true ); $response = ft_api_process_form($params); list($success, $error_code) = $response; $fields['success'] = $success; $fields['error_code'] = $error_code; $json=json_encode($fields); echo $json; ft_api_clear_form_sessions(); PS: Im using DATABASE Sessions ideas?? Ok, I worked out that it ONLY sends emails if there is a Thank You Page. Which is a problem because my AJAX php handler needs to return JSON and NOT direct to a thank you page..... OK, in the API.php changed this if ($passes_captcha && !empty($next_page) && !$is_deleting_file) { // if the user wasn't putting through a test submission or initializing the form, we can send safely // send emails at this juncture, but ONLY if it was just finalized OR if the send_emails parameter // allows for it if ($form_id != "test" && $submission_id != "test" && !isset($_SESSION[$namespace]["form_tools_initialize_form"]) && !isset($form_data["form_tools_ignore_submission"])) { // send any emails attached to the on_submission trigger if (isset($params["send_emails"]) && $params["send_emails"] === true) ft_send_emails("on_submission", $form_id, $submission_id); else if ($is_finalized == "yes" && (!isset($params["send_emails"]) || $params["send_emails"] !== false)) ft_send_emails("on_submission", $form_id, $submission_id); } header("location: $next_page"); exit; } to this SO IT WILL SEND EMAILS IF NO PAGE TO REDIRECT TO if ($passes_captcha && !$is_deleting_file) { // if the user wasn't putting through a test submission or initializing the form, we can send safely // send emails at this juncture, but ONLY if it was just finalized OR if the send_emails parameter // allows for it if ($form_id != "test" && $submission_id != "test" && !isset($_SESSION[$namespace]["form_tools_initialize_form"]) && !isset($form_data["form_tools_ignore_submission"])) { // send any emails attached to the on_submission trigger if (isset($params["send_emails"]) && $params["send_emails"] === true) ft_send_emails("on_submission", $form_id, $submission_id); else if ($is_finalized == "yes" && (!isset($params["send_emails"]) || $params["send_emails"] !== false)) ft_send_emails("on_submission", $form_id, $submission_id); } if (!empty($next_page) && $next_page != ""){ header("location: $next_page"); exit; } } RE: Emails not sent from API (Using AJAX) **FIXED** - whtknt - Mar 13th, 2013 Just wanted to say THANK YOU! This one stumped me all day and after several hours of troubleshooting, your solution solved the issue in seconds. Hopefully this can be accounted for in future releases or updates. Ideally, an AJAX response system could even be built in. |