We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    I've created a multipage form with FormIt and formItRetriever. I would like to have a 'back button' in the form. Would this be possible using formitRetriever? Right now, the submit button forwards to the next formpage and with formitRetriever, the values are passed on as well. Maybe it would also be possible to go back to a previous formpage and have the previous values filled in with formitRetriever? I'm not sure how to give the 'back button' that action to go back to the previous page and make this work. Anyone can help me out?

    And another question (sorry if this is a dumb question): am I right that the form values filled in by different users can never get mingled when I use formitRetriever? (if multiple users fill the form in at the same time..?)
      • 4172
      • 5,888 Posts
      Hi Michelle,
      I do multipage-forms with formit, all on the same page.
      I manage the different form-parts and formit-calls with bloX. Its also possible to go back and forward between forms with this method.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 19328
        • 433 Posts
        Oh laugh
        For everything I need, you seem to have the answer Bruno ;-)
          • 19328
          • 433 Posts
          Alright, I've been trying something on my own. My idea is to have two submit buttons, and with a custom hook check which one is clicked. Based on that I forward to the previous form page or the next.
          Now I want the filled in values to display with formItRetriever, be it going back or forth. It's not working though... I'm going crazy over this ;-)

          FORM 1 (ID 22) (this one is just forwarding)
          [[!FormIt? &hooks=`redirect` &store=`1` &redirectTo=`30`]]
          [[!FormItRetriever]]
          
          <form class="form" action="[[~[[*id]]]]" method="post">
          <input type="hidden" name="naam" value="[[!+fi.naam]]" />	
          	<label for="content">
          	        Reactie:
          	        <span class="error">[[+fi.error.content]]</span>
          	    </label>
          	    <textarea id="reactie" cols="55" rows="7" name="reactie:required:stripTags">[[!+fi.reactie]]</textarea>
          	
          	<div class="form-buttons">
          		<input type="submit" value="Verder!" />
          	</div>
          </form>


          FORM 2 (back and forth)

          [[!FormIt? &hooks=`backOrForward` &store=`1`]]
          [[!FormItRetriever]]
          
          <form class="form" action="[[~[[*id]]]]" method="post"><input type="hidden" name="nospam:blank" /> <input type="hidden" name="resource_id" value="[[!+fi.id]]" /> 
          <input type="hidden" name="genomineerde_id" value="[[!+fi.genomineerde_id]]" />
          <input type="hidden" name="reactie_id" value="[[!+fi.reactie_id]]" />
          
          
          <label for="naam"> Naam: <span class="error">[[+fi.error.naam]]</span> </label> 
          <input id="naam" type="text" name="naam:required" value="[[!+fi.naam]]" />
          
          <div class="form-buttons">
          <input type="submit" name="previous" value="Terug!" />
          <input type="submit" name="next" value="Verder!" />
          </div>
          
          </form>
          


          And the snippet I made (backOrForward):

          $modx->log(modX::LOG_LEVEL_ERROR,'START BACK OR F0RWARD');
          
          if (isset($_POST['next'])) {
           $modx->log(modX::LOG_LEVEL_ERROR,'next clicked');
          	$url = $modx->makeUrl(31);
          	$modx->sendRedirect($url);
          } else if (isset($_POST['previous'])) {
           $modx->log(modX::LOG_LEVEL_ERROR,'previous clicked');
          	$url = $modx->makeUrl(22);
          	$modx->sendRedirect($url);
          } else {
           $modx->log(modX::LOG_LEVEL_ERROR,'nothing clicked');
          	$url = $modx->makeUrl(100);
          	$modx->sendRedirect($url);
          }


          The back and forth forwarding works, but the values are not stored.
            • 19328
            • 433 Posts
            Can't modify my post anymore, but form 2 has ID 30, and resource 31 is a thank you page.
              • 4172
              • 5,888 Posts
              because you're redirecting before formit can store the request, you can't get the datas.

              you can try to do the redirection with an additional snippet, placed after formit, not in a formit-hook.
              To be sure, the form has validated you can set a placeholder or something in your formit-hook and read that placeholder by your snippet, before redirecting.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 19328
                • 433 Posts
                Thanks, I'm going to give it a try.
                Why would the redirect hook work, and my own hook not? Doesn't the redirect hook do the same: redirect to another location?
                  • 19328
                  • 433 Posts
                  Wow Bruno, you're so smart smiley!
                  It's working (not with the validation check, haven't tried that yet).
                  I'll post the code later on for others who might be interested.

                  By the way, before I get carried away, is this a good / safe etc. way to do this?
                  Is it not possible that data from a wrong user gets displayed in the form?
                    • 4172
                    • 5,888 Posts
                    I think this two functions should answer your questions:

                        /**
                         * Gets a unique session-based store key for storing form submissions.
                         *
                         * @return string
                         */
                        public function getStoreKey() {
                            return $this->modx->context->get('key').'/elements/formit/submission/'.md5(session_id());
                        }
                    


                        /**
                         * Handle post-processing through postHooks
                         * @return bool
                         */
                        public function postProcess() {
                            $success = $this->runPostHooks();
                            if ($success) {
                                /* if store is set for FormItRetriever, store fields here */
                                $store = $this->modx->getOption('store',$this->config,false);
                                if (!empty($store)) {
                                    $this->dictionary->store();
                                }
                    
                                /* if the redirect URL was set, redirect */
                                $this->checkForRedirect();
                    
                                /* set success placeholder */
                                $this->setSuccessMessage();
                    
                                /* if clearing fields on success, just end here */
                                if ($this->modx->getOption('clearFieldsOnSuccess',$this->config,true)) {
                                    $this->clearFieldsAtEnd = true;
                                }
                            }
                    
                            return $success;
                        }
                    

                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 19328
                      • 433 Posts
                      Thank you.
                      Those are from formit I see.
                      Ah, redirect happens after store. That explains.
                      And the first function means that for each user, the data is stored in a unique way, if I understand correct.

                      Well, that's a relief smiley