Aug 18th, 2009, 6:35 AM
(This post was last modified: Nov 4th, 2009, 4:17 PM by sergiozambrano.)
Ben has been kind enough to try the error right in my form, so here's his message plus a few edits.
Replace your if(empty($errors)) statement by the following:
(replace your button's name attribute, next page finlename with yours)
There were two situations that weren't working:
(1) When the PHP validation failed (e.g. invalid email address), $fields wasn't being updated with the latest & greatest form field content. So these lines take care of that:
else
$fields = array_merge($fields, $_POST);
(2) when the user entered CAPTCHA incorrectly, again the $fields variable wasn't being updated with the latest content. So what I did was merge the content stored in $_SESSIONS (which IS up to date) with $fields. This ensures $fields has the latest content for displaying in the page.
$fields = array_merge($fields, $_SESSION["form_tools_form"]);
In terms of a long term fix, I'm going to have to think some more about this. Issue (1) is something that will have to be handled in the form code, so that won't change. But for (2), it seems like ft_api_process_form() should return an updated version of $fields when the user fails CAPTCHA. So expect an update to the API at some point that makes that step a little simpler (don't worry, though - it will be compatible with this code so you can upgrade in safety).
Replace your if(empty($errors)) statement by the following:
(replace your button's name attribute, next page finlename with yours)
PHP Code:
if (empty($errors)) {
$params = array(
"submit_button" => "contact_submit",
"next_page" => "thankyou.php",
"form_data" => $_POST,
"finalize" => true
);
ft_api_process_form($params);
$fields = array_merge($fields, $_SESSION["form_tools_form"]);
} else {
$fields = array_merge($fields, $_POST);
}
}
?>
There were two situations that weren't working:
(1) When the PHP validation failed (e.g. invalid email address), $fields wasn't being updated with the latest & greatest form field content. So these lines take care of that:
else
$fields = array_merge($fields, $_POST);
(2) when the user entered CAPTCHA incorrectly, again the $fields variable wasn't being updated with the latest content. So what I did was merge the content stored in $_SESSIONS (which IS up to date) with $fields. This ensures $fields has the latest content for displaying in the page.
$fields = array_merge($fields, $_SESSION["form_tools_form"]);
In terms of a long term fix, I'm going to have to think some more about this. Issue (1) is something that will have to be handled in the form code, so that won't change. But for (2), it seems like ft_api_process_form() should return an updated version of $fields when the user fails CAPTCHA. So expect an update to the API at some point that makes that step a little simpler (don't worry, though - it will be compatible with this code so you can upgrade in safety).