SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Step though SESSION array after page redirect

    Hello!

    I'm receiving data in the URL that tells me if a person wants to do something NOW or LATER.
    I have a series of surveys that need to display one after another.
    I would like to show the survey's marked as NOW first, then show the survey's marked as LATER.

    The first URL I receive will look something like this: surveygroup.php?suvey1=NOW&survey2=LATER&survey3=NOW&survey4=&survey5=LATER

    The order I want to show the survey's would be:
    1. survey1
    2. survey3
    3. survey2
    4. survey5
    (skip survey4)

    The trouble starts after the first survey is submitted. Because I'm using a 3rd party to handle the forms, I need to redirect back to my page. The redirect URL could tell me which form was just filled out. But I'll need to keep the arrays in the global $_SESSION so I can somehow keep stepping through the NOW and LATER arrays.

    I've got this so far:
    PHP Code:
    if (!empty($_GET['survey1'])) {
      if(
    $_GET['survey1'] == 'NOW') {
        
    $now[] = 'survey1';
      } else {
        
    $later[] = 'survey1';
      }
    }
    // repeat for each survey...

    $_SESSION['now'] = $now;
    $_SESSION['later'] = $later
    Once the first survey is submitted, I would need to move the array pointer to the next survey in the NOW array. Once I'm at the end, I would start the LATER array, until I reached the end of that array, and show a thank you message.

    If this makes sense to you, that's wonderful! If you have a suggestion for me, I'd greatly appreciate it.

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Just merge them together, then have an extra session variable that tracks progress.

    $_SESSION['survey_list'] = array_merge($_SESSION['now'], $_SESSION['later');

    Now you can just store the value like "3" in another session variable, and you'll know that 3 is completed (or current depending on how you want to code the logic)


    Also
    if (!empty($_GET['survey1'])) {
    if($_GET['survey1'] == 'NOW') {
    $now[] = 'survey1';
    } else {
    $later[] = 'survey1';
    }
    }

    Can be done with a for loop (for i=1;i<=5;$i++); and repeat the code to prevent code duplication.

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the response wonshikee. I like the merge idea, then run through the one array.

    The part I'm stuck on is how to keep track of the progress. I don't understand how I can know which survey to load, or where I am in the array after each redirect.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •