0

I have a form that has 3 steps. I use SESSIONS to keep values from step to step. When I open the same form in another tab and complete the first step, this immediately replaces the Session values from the other form.

So how can I create sessions with field values that are attached to a specific form? I need to avoid Session conflicts.

George D.
  • 1,630
  • 4
  • 23
  • 41
  • are you checking if the variable/session has been set before you replace session values? Also some sample code might help us answer your question. – Class Jan 20 '13 at 23:15
  • My code is extremely complicated and it'll not help. I use a framework and a Template engine to generate the forms. – George D. Jan 21 '13 at 00:03

2 Answers2

0

If the forms are indeed different, then put it in a multi-dimensional array:

$_SESSION['register']['field1']=$_POST['field1'];

$_SESSION['contact']['field1']=$_POST['field1'];

If it is the same form and it is just a new tab, you can either check if the value was set before and ignore it, set a flag to say there is a form submission in progress, or entirely delete the old session values so the new form in the new tab has no values attached.

Tim Withers
  • 12,072
  • 5
  • 43
  • 67
  • I thought of something like this, but if the user close the first window then the Session will remain open,so the site will not accept any other form until the session value expires. – George D. Jan 21 '13 at 00:06
  • 1
    Why not just reset the session when the first page of the form is visited again... OR on the first page of the form, check for the session variables and forward the user to the current page they should be on. – Tim Withers Jan 21 '13 at 00:07
  • hm...point the user to the page they should be on? This maybe the greatest Idea to bypass such a problem! – George D. Jan 21 '13 at 00:09
  • 1
    Brilliant Tim, I'll try that tomorrow. I'll store the current URL in the Session and redirect the user in case a new form is triggered. So damn simple and so great. I really thank you. – George D. Jan 21 '13 at 00:12
  • Can you edit your answer with this info ( redirect to the right url) so I can mark it as the answer? – George D. Jan 21 '13 at 09:38
0

I use this function to handle form input:

function Hold_Form_Input($formname)
    {
    $FormPost = array();
        foreach ($_POST as $key => $entry)
            {
                $FormPost[$key]= $entry;
            }
     $_SESSION[$formname]= $FormPost;           
    }

And I pass the form name in with a hidden input.

ROY Finley
  • 1,406
  • 1
  • 9
  • 18