We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8877
    • 12 Posts
    I have posted about this before but the more i think im understanding the more im getting confused sad

    I think im going to put my head through the wall soon smiley

    What i want to do seems so simple but i just dont have the php knowledge to do it sad

    I have an enquiry form on my rentals website .... the customer ticks what they are interested in i.e tv’s or fridges
    then clicks submit enquiry and i call them on the phone number they supply this is easy for me to do.

    What i would prefer ... and what i have been trying to do is have a button on each of my product pages such as
    the Television Page that says [ADD TO ENQUIRY] which they click and then continue to browse on to another page
    and repeat the process ...

    its kind of like a cart but without actual products what i was hopeing to do was use the
    [*page_title*] placeholder as the product name as the pages are already called Televisions, Fridges, ECT ....

    So when they click the [ADD TO ENQUIRY] button it just remembers the page name "somewhere" (not in the database! but maybe in this mystical php session that i just dont understand sad ... ) and then once they are ready they could click [PLACE YOUR ENQUIRY] and they would be sent to a form which already knows what items they wish to enquire about and then they only need to put in name and phone number and hit [SUBMIT]

    Now some helpful people have given me some one line answers like just store it in a php session but i dont understand
    if anyone would be kind enough to give me a simple but more detailed explanation:

    Including how do i add to the session variable? do i use a form? php snippet? HELLLLPPPPPPP smiley

    i would be VERY VERY Greatfull for any help smiley
      • 8877
      • 12 Posts
      Okay i think ive figured it out but just a nother little quick question

      when i place this code into a snippet:

      <?php
      foreach($_SESSION['goodies'] as $item) { 
      echo 'I see you would like to rent our ' . $item; 
      }
      ?>


      it returns the following error:

      « MODx Parse Error »
      MODx encountered the following error while attempting to parse the requested resource:
      « PHP Parse Error »

      PHP error debug
      Error: Invalid argument supplied for foreach()
      Error type/ Nr.: Warning - 2
      File: /var/www/html/manager/includes/document.parser.class.inc.php(769) : eval()’d code
      Line: 2

      Parser timing
      MySQL: 0.0061 s (4 Requests)
      PHP: 0.0398 s
      Total: 0.0458 s
        • 3749
        • 24,544 Posts
        Is the session variable an array? It needs to be to do it that way.

        Is it set? you can check with:

        print_r($_SESSION['goodies'];


        You should always check to make sure there’s something to process before working with it:

        if (isset($_SESSION['goodies'])) {
            foreach($_SESSION['goodies'] as $item) { 
            echo 'I see you would like to rent our ' . $item; 
        } else {
            echo 'Session variable not set';
        }

          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
          • 3749
          • 24,544 Posts
          BTW, here’s another way to go. You could make the $_SESSION variable a comma-delimited string (e.g. ’tvs,vcrs,toasters’). I think it might be easier to understand than updating an array:

          On submit, you’d do this (assuming that $pt is set to the pagetitle):

          if (isset($_SESSION['goodies'])) {  // there's already something there
          
             $str = $_SESSION['goodies'];   // get it
             $str = $str . ',' . $pt;   // append comma and new pt
             $_SESSION['goodies'] = $str;  // set the new string
          
          } else {  // it's empty, no comma necessary - just add the new one
          
             $_SESSION['goodies'] = $pt;
          
          }


          When you need to process the choices:

          $productArray = array();
          
          if (isset($_SESSION['goodies'])) {
          
             $productArray = explode("," ,  $_SESSION['goodies']);  // get the product array from the string in the session variable
          
              foreach($productArray as $product) {
                  echo 'you want information on ' . $product . '<br />';
              }
          
          } else {
            // session variable not set, do something else.
          }


            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