Form Tools
Weird: form submitting into another forms's DB - 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: Weird: form submitting into another forms's DB (/showthread.php?tid=1327)



Weird: form submitting into another forms's DB - heywood7 - May 25th, 2011

I recently created a duplicate of an existing form. The new form contained a few new fields, but is otherwise identical. My goal was to continue using the existing form while I make edits to the new form.

I successfully created the new form through the Form Tools wizard, and each form has a unique ID. A quick peak into the database reveals that there is a table for each form. I also have a unique "thank you" page for each form. So far so good.

However, when I submit the new form it enters the values into the table of the old form and sends out an email that is tied to the old form. I temporarily disabled the old form in hopes that the new form might go through correctly, but I get a 303 error.

The $fields values are correctly set in both files, so I'm not sure where to look next.


RE: Weird: form submitting into another forms's DB - JMW - May 25th, 2011

If you are going to have multiple forms, you need tomake sure that each one has unique field names, otherwise you may get "crosstalk" between them if both are active at the same time. I found that out the hard way because the sessions info was being overwritten because the fields names were the same in both forms, regardless that they both had unique ID's.

I know it's a pain, but go through one of them and make all the fields names unique and there is no duplication between the two forms.

Odd, because a 303 error is that the form has been disabled, so it shouldn't be uploading anything. Rename all the field names in the new form, edit the database for it accordingly and see if that fixes it.


RE: Weird: form submitting into another forms's DB - heywood7 - May 26th, 2011

(May 25th, 2011, 7:32 PM)JMW Wrote: If you are going to have multiple forms, you need tomake sure that each one has unique field names, otherwise you may get "crosstalk" between them if both are active at the same time. I found that out the hard way because the sessions info was being overwritten because the fields names were the same in both forms, regardless that they both had unique ID's.

I know it's a pain, but go through one of them and make all the fields names unique and there is no duplication between the two forms.

Odd, because a 303 error is that the form has been disabled, so it shouldn't be uploading anything. Rename all the field names in the new form, edit the database for it accordingly and see if that fixes it.

JMW - Thanks for the suggestion. The field name are indeed identical. I'll update the fields and post back with the results.



RE: Weird: form submitting into another forms's DB - Ben - May 28th, 2011

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


RE: Weird: form submitting into another forms's DB - im4u_fforum - Jun 21st, 2013

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