We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20999
    • 20 Posts
    So I have a page with a form, and after submitting that form, i create an array of the stored information and redirect to another page. Then from this page I call the template array, and it is apparently not set!!! What is going on!!!?
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: nathan at Aug 09, 2007, 04:21 PM

      So I have a page with a form, and after submitting that form, i create an array of the stored information and redirect to another page. Then from this page I call the template array, and it is apparently not set!!! What is going on!!!?
      PHP does not maintain variables or state of any kind between requests (a la redirects), other than through PHP session variables. Without code, it’s very hard to intuit what you are doing however.
        • 20999
        • 20 Posts
        OK, let me provide some code... Sorry about that.

        So I have a basic html form and I pull data from that with instruments.php shown below:

        The snippet:
        <?php
        include_once($modx->config['base_path'].'assets/quoteForm/scripts/instruments.php');
        ?>
        


        here is instruments.php
        <?php
                require_once "HTML/Template/IT.php";  //pear template class
                require_once "functions.php"; //my functions
        
                session_start(); //start/continue the session
                $formConnect = connectAndSelect(); //connect to database
        
                $contactInfo = array();
                $contactInfo['FirstName'] = $_REQUEST['FirstName'];
                $contactInfo['LastName'] = $_REQUEST['LastName'];
                $contactInfo['CompanyName'] = $_REQUEST['CompanyName'];
                $contactInfo['Address'] = $_REQUEST['Address'];
                $contactInfo['Address2'] = $_REQUEST['Address2'];
                $contactInfo['City'] = $_REQUEST['City'];
                $contactInfo['State'] = $_REQUEST['State'];
                $contactInfo['Zip'] = $_REQUEST['Zip'];
                $contactInfo['Phone'] = $_REQUEST['Phone'];
                $contactInfo['Email'] = $_REQUEST['Email'];
                $contactInfo['Application'] = $_REQUEST['Application'];
        
                /************************
                I took out all the PEAR code because it really does not matter
                *************************/
        
                mysql_close($formConnect);
                //$template->show();  //show template with pear 
                header("Location: http://tautheta.in-situ.com/assets/quoteForm/scripts/instrumentInfo.php");
        ?>
        


        At this point so far everything works just fine. But when I redirect to the instrumentInfo.php script....

        <?php
                session_start();
        
                $productQty = $_SESSION['productQty'];
                $contactInfo = $_SESSION['contactInfo'];
        
                //if user has no contact info set, redirect them to the beginning of the form
                if (!(isset($_SESSION["contactInfo"]))){
                        die("ERROR: contact info session var not set....");
                }
                else if (!isset($_REQUEST["instrument"]))
                        die("Please go back and select an instrument before proceeding.  Thank you!");
                else
                        $instrument = $_REQUEST['instrument'];
                        $_SESSION["instrument"] = $instrument;
                        $productQty[(string)$instrument] = 1;
        
                //...
                //There is more code here but it doesn't really matter
        ?>
        


        I set the $_SESSION[’contactInfo’] to the local variable $contactInfo, and when I test to see if $contactInfo is set, it fails. When I tested this outsite of MODx, it worked just fine. I suppose I could make instrumentInfo.php in to a snippet, but including instrumentInfo.php, but I don’t think that would really matter. So why is $_SESSION[’contactInfo’] not set?
          • 22303 MODX Staff
          • 10,725 Posts
          First, remove the session_start() stuff, as that is unnecessary. MODx takes care of starting the session.

          Second, yes, I believe you need to include these things as snippets, otherwise, you are not even in a MODx session. You are likely in a session for the stand-alone script you are executing following that redirect.
            • 20999
            • 20 Posts
            Thank you! That worked perfectly!