We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6902
    • 126 Posts
    I have a 4-page form workflow that I am having trouble with. I am using a $_SESSION variable to keep data between pages. Users can go back and forth freely between the first 3 pages with the data persisting between them. The 4th page should display all the submitted data and clear the session variable... and this is where I'm running into issues. Here's a simplified version of my page 4 code:

    <?php
    if ( empty($_SESSION['submittedData']) ) {
    	// redirect to page 1
    }
    
    $data = $_SESSION['submittedData'];
    $output = '';
    
    $output .= $data['item1'];
    $output .= $data['item2'];
    // etc.
    
    unset($_SESSION['submittedData']);
    
    return $output;
    
    


    This snippet will invariably bounce the user back to page 1 erasing all of their data. If I comment out the "unset" line, the page loads and displays properly—but the session isn't cleared, of course.

    Is there a better way to do this? Why is this happening?
      • 6902
      • 126 Posts
      Whoops... forgot to add... This is Revo 2.2.4
        • 3749
        • 24,544 Posts
        Is there any way the snippet could be running twice (say, a snippet tag in the $output)? That would explain what you're seeing.


        ------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using.
        MODX info for everyone: http://bobsguides.com/modx.html
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 6902
          • 126 Posts
          The snippet isn't running twice. The output is just a string of html, and the snippet is only getting called once on the page... in fact, there isn't much else to the page but the snippet.
            • 32316
            • 387 Posts
            How do you know it is not running twice?

            I ask because I had a very simple snippet that was meant to count page views, but would often not run and sometimes would run twice! I never did get to the bottom of it - was not worth the time.

            For testing purposes try an echo or print_r() before the unset and see what happens - this not a solution but just for testing!
              • 6902
              • 126 Posts
              That does sound weird. I will give the echo a go and see if it is doing something funky. I can't imagine, though, why it would be running twice based on my code, thus if it is running twice, I don't think I would know how to fix it—if it were even possible. I'll post again shortly with the results.
                • 32316
                • 387 Posts
                I should have noted that my simple snippet to count page views worked flawlessly for 6-9 months, so it was probably an modx upgrade that resulted in it not counting - I suspect it has something to do with cache but I am really not sure and so do not want to lay any blame.
                  • 3749
                  • 24,544 Posts
                  Do any of the variables you're returning in the output contain the snippet tag? That would also explain what you're seeing.


                  ------------------------------------------------------------------------------------------
                  PLEASE, PLEASE specify the version of MODX you are using.
                  MODX info for everyone: http://bobsguides.com/modx.html
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting