FORUMS


The Form Tools forums are no longer active, but the old posts have been archived here. Please see the Help page on how to get help / report issues.

Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Emails not sent from API (Using AJAX) **FIXED**
#1
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;
}
}

Reply
#2
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)