Hello Ben,
I have used your functions into my forms. However, when one field of the form is entered correctly while the other is not the error displays correctly for the incorrect entry but all the field entries (even the correct ones) disappear!
Could you advise please?
On my contact Page:
<?php
require_once("/..../...../ftoolslgobal/api/api.php");
$fields = ft_api_init_form_page(X, "live", "myform");
$errors = array();
if (isset($_POST['submit2']))
{
$rules = array();
$rules[] = "required,fname,I need your name!";
$rules[] = "required,sname,I need your surname!";
$rules[] = "required,email,I need your contact email address!";
$errors = validate_fields($_POST, $rules);
if (empty($errors))
{
$params = array(
"submit_button" => "submit2",
"next_page" => "thankyou.php",
"form_data" => $_POST,
"finalize" => true,
"namespace"=>"myform"
);
ft_api_process_form($params);
}
else
{
$fields = array_merge($_SESSION["form_tools_form"], $_POST);
}
}
?>
On my thank you page:
<?php
require_once("/...../...../......./ftools/global/api/api.php");
$fields = ft_api_init_form_page();
ft_api_clear_form_sessions ("myform");
?>
many thanks
Alok
(May 28th, 2011, 2:25 PM)Ben Wrote: Hi guys,
I sat down to look at this tonight & to come up with a decent solution, and it turns out I'd actually already added one in (!). I'm so sorry for not mentioning it sooner, but quite honestly I don't remember adding it. I just tested it out and it seems to work fine.
I'll this up in much more detail in a tutorial, but for now, here's how to configure it properly to allow you to have users submitting multiple API forms at the same time and not get the session data mixed.
These are the three functions that you use for API forms:
ft_api_init_form_page
ft_api_process_form
ft_api_clear_form_sessions
All three of them allow you to pass in a unique namespace that will be used for a particular form. A "namespace" is just a way to partition something off from other things.
What you'll need to do is come up with a string for each form (e.g. "form1" and "form2" - that will act as your namespace). Then make the following changes to your function calls. The following is for your first form (which we're going to give a "form1" namespace).
Code:
// 1. Change this line on EVERY page:
ft_api_init_form_page(X); // X is your form ID (or it's not explicitly passed)
// to this:
ft_api_init_form_page(X, "live", "form1"); // same on every page
// 2. in the $params passed to your ft_api_process_form() function, add in an
// extra key-value pair: "namespace" => "form1" (again, on EVERY page)
// 3. On your final page, change this:
ft_api_clear_form_sessions();
// to this:
ft_api_clear_form_sessions("form1"); // this now only empties the sessions for form 1
Then do exactly the same thing for your second form, only with the "form2" namespace.
And that should be it...
Do let me know how it goes.
- Ben