We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17301
    • 932 Posts
    Hi,

    Does anyone have any experience or know how I would go about creating a lengthy stepped form with dynamic questions that isn't reliant on javascript?

    To paint the picture a little more I'm going to create a form with a series of questions on page A. Once the user submits page A I'd like them to be taken to either page B or C depending on the answers they give and of course I'd like the entire session to be tracked to the user and eventually after 3 or 4 steps be emailed across as normal.

    Is the only/best way for me to do this to capture page/form A and set the redirect to a value that will determine the following set of questions, and then use formitretriever to retrieve all the values from page A into hidden input fields? It seems very redunant to capture loads of hidden fields especially after 4 or 5 pages - is there a smarter way to achieve this?

    Thanks,
      ■ email: [email protected] | ■ website: https://alienbuild.uk

      The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
      • 3749
      • 24,544 Posts
      I would actually use JavaScript, since all pages could be on tabs allowing the user to return to previous pages. It would also allow validating each page when the user switches tabs to the subsequesnt page.

      Barring that, rather then FormIt, I think I'd use a single snippet that saved the relevant fields and an indicator of which page ('form_page') the user was on in $_SESSION variables. Then I'd put the forms for each page in separate chunks. Be sure to put the snippet tag at the top of each chunk and make the form action the current page.

      if (! isset($_SESSION['form_page'') {
          $output =  $modx->getChunk('form_page_1');
      } else {
          switch($_SESSION['form_page']) {
              case 'page_1':
             /* save the session variables from the $_POST */
             $SESSION[form_page] = 'page_2';
             $output = $modx->getChunk('form_page_2');
      
         case page_2:
           /* Get any variables that need to be passed on from the $_SESSION */
           /* Save the session variables from the $_POST + the $_SESSION ones collected above */
           $SESSION[form_page] = 'page_3';
           output = $modx->getChunk('form_page_3');
      
           // etc.
      }
      
      return $output;


      This will get very hairy if you want to let users return to the previous pages or need to validate each page. wink

      On reflection, FormIt might work better for this since you could use hooks and preHooks to help with moving between pages.

      OR: There are a lot of packages out there that are made for exactly this purpose, though I've never used any of them.


        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
        • 17301
        • 932 Posts
        Thank you, Bob. I'll investigate further and report back.
          ■ email: [email protected] | ■ website: https://alienbuild.uk

          The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.