Jan 13th, 2012, 11:37 AM
Ah! Yeah, this is an old problem which really should have been solved "out the box"; I just couldn't think of a good way to do it automatically.
As you noted, the form data gets combined / overwritten when going from one API form to another without completing the process. Completing a form will wipe out sessions so the next submission (in whatever form) will be completely separate. But if you visit one form then another, the code doesn't know the different & submits the data to the wrong form.
Bad indeed!
To allow for multiple API forms to be entirely independent of one another, you need to namespace the sessions for each form. All (relevant) API functions contain a way to specify the namespace. To be clear, this just lets you store the form data in a unique location for each form, so no two forms submissions in different forms every get mixed.
In brief, you need to update the following functions in all of your forms:
ft_api_init_form_page()
This function calls probably looks something like:
ft_api_init_form_page(10);
or
ft_api_init_form_page();
depending on where in the form they are.
Change them to:
ft_api_init_form_page(10, "", "namespace1");
and
ft_api_init_form_page("", "", "namespace1");
respectively.
ft_api_process_form()
For this function, include a new "namespace" => "namespace1" key-value pair being passed to it via the single param.
ft_api_clear_form_sessions()
Change these calls to:
ft_api_clear_form_sessions("namespace1");
Then, it will only clear sessions for that form only.
Each form will need to pass the same unique namespace to every API function. So form #1 would have (for example) "namespace1" as the namespace; form #2 would have "namespace2".
You can call them whatever you want - just so long as they're consistent throughout the form, and unique only to that form.
Yeesh, reading over the above it kind of feels like I'm writing in Swahili. Hope this is clear... let me know if not.
- Ben
As you noted, the form data gets combined / overwritten when going from one API form to another without completing the process. Completing a form will wipe out sessions so the next submission (in whatever form) will be completely separate. But if you visit one form then another, the code doesn't know the different & submits the data to the wrong form.
Bad indeed!
To allow for multiple API forms to be entirely independent of one another, you need to namespace the sessions for each form. All (relevant) API functions contain a way to specify the namespace. To be clear, this just lets you store the form data in a unique location for each form, so no two forms submissions in different forms every get mixed.
In brief, you need to update the following functions in all of your forms:
ft_api_init_form_page()
This function calls probably looks something like:
ft_api_init_form_page(10);
or
ft_api_init_form_page();
depending on where in the form they are.
Change them to:
ft_api_init_form_page(10, "", "namespace1");
and
ft_api_init_form_page("", "", "namespace1");
respectively.
ft_api_process_form()
For this function, include a new "namespace" => "namespace1" key-value pair being passed to it via the single param.
ft_api_clear_form_sessions()
Change these calls to:
ft_api_clear_form_sessions("namespace1");
Then, it will only clear sessions for that form only.
Each form will need to pass the same unique namespace to every API function. So form #1 would have (for example) "namespace1" as the namespace; form #2 would have "namespace2".
You can call them whatever you want - just so long as they're consistent throughout the form, and unique only to that form.
Yeesh, reading over the above it kind of feels like I'm writing in Swahili. Hope this is clear... let me know if not.
- Ben