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:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending the wrong data when using 2 forms

I installed formtools with succes but having this strange issue.

On my site I use two forms; one on the page "aanvraag informatie" where a visitor can subscribe to receive information, and one on the page "inschrijving" where can be subscribed for joining a workshop.

Everything works as it should when you directly go to the right page an fill in the form. The data is saved right and also the right confirmationmail is send.

However, when a visitor first goes to one of the pages, then -without filling any field- decides he has to use the other form and goes there, the data is send wrong.

example: I visit : "inschrijving", decide i've got the wrong page and go to "aanvraag informatie". I fill in the form and send it. Then the data is send to "inschrijving" and also the confirmationmail from "inschrijving" is send.

I tried disabling the cache and several other things, but I can't solve it.

I hope you understand my problem and can help me with it.

Hi Petran,

Ah, what's happening is that when you go to a form page, the API sets up sessions for that individual form. When you go to the NEXT form, the sessions are still remembered from the last one, and cause the problem you mentioned.

Interesting this problem hasn't been brought up before, actually...

What you need to do is empty the sessions cache when flipping between forms. I'd probably do it like this. Right after the require("/path/to/api.php"); line in each of your forms add this:

PHP Code:
// X should be the form ID of your form on each page
if (isset($_SESSION["form_tools_form"]["form_tools_form_id"]) && $_SESSION["form_tools_form"]["form_tools_form_id"] != X) {

That checks to see if the form ID in memory is different from the current form, and if so, empties it. (Weirdly, the ft_api_init_form_page(X) function call is needed here: the ft_api_clear_sessions() function needs it to have been called beforehand. I plan on fixing this at some point).

After that, you'll already have your own ft_api_init_form_page() function (already in your form), which will re-initiate sessions - and everything should work smoothly.

I confess, I haven't tested this, but it should work fine... knock on wood. Smile

- Ben
It does work ...however.

The forms I mentioned earlier are one single-page form and the other is a multi-page form.

I inserted the code in both forms. It does work for the multi-page form, but not for the single-page one.

I tried to play around with your code and found that only adding ft_api_clear_sessions(); did work.

It seems a bit strange to me, but I'm not a programmer. I would appreciate if you could look at this again.


Forum Jump:

Users browsing this thread: 1 Guest(s)