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

    I have a multipage form. I want to direct to a page based on a value of a field from the first form. So I ditched redirect and wrote a little custom hook using

    $url = $modx->makeUrl($nextpage);
    $modx->sendRedirect($url);


    which works just fine, except that Formretriever only seems to retrieve stored data if redirect is used. If redirect is used, the values from form 1 are transferred but redirects to a single fixed page in redirectTo. But if redirect isn't used and I use my little snippet instead, no values are retrieved.

    Any ideas what I can do? Seems odd that Formitretriever is so tightly linked to redirect.

    thanks

    David Heriot
      David Heriot
      pfsmedia
      • 9439
      • 90 Posts
      I can see that's maybe a bit simple. Now I have a snippet called altRedirect:

      $nextpage = $hook->getValue('number-required');
      $modx->setPlaceholder('gotopage', $nextpage);
      return true;


      And the Formit call:

      [[!FormIt?
      &hooks=`FormItSaveForm,altRedirect,redirect`
      &validate=`number-required:required:minLength=`1``
      &store=`1` 
      &redirectTo=`[[+gotopage]]`
      &submitVar=`go`
      ]]


      But doesn't work. When I look at the log it says:

      `[[+gotopage]]` is not a valid integer and may not be passed to makeUrl()

      When I write the variable and the placeholder to the log it says:

      nextpage variable is: 45
      placeholder, ie gotopage, is: 0

      So is this line in the snippet, $modx->setPlaceholder('gotopage', $nextpage);, incorrect?
        David Heriot
        pfsmedia
        • 9439
        • 90 Posts
        Ok, I'm sure this is nearly cracked, except for the return from the snippet to the redirectTo. If "`[[+gotopage]]` is not a valid integer.." then this means that redirect is just looking at a string of letters, rather than a number. How difficult can it be to pass the number from the snippet to the redirectTo?

        Stuck. Help, someone.
          David Heriot
          pfsmedia
          • 9439
          • 90 Posts
          The problem seems to be returning the value from the snippet. I now have:

          $nextpage = $hook->getValue('number-required');
          if ( $nextpage == 3 ) {
            $nextpage = $nextpage + 29;
          } 
          else {
            $nextpage = $nextpage + 41;
          }
          $modx->log(modX::LOG_LEVEL_ERROR, 'nextpage is: '.print_r($nextpage,true));
          $hook->setValues(array(
              'gotopage' => $nextpage
          ));
          
          return true;

          and
          [[!FormIt?
          &hooks=`altRedirect,redirect`
          &validate=`number-required:required:minLength=`1``
          &store=`1` 
          &redirectTo=`[[+gotopage]]`
          &submitVar=`go`
          ]]


          If I dump $hook to the log, it returns "[redirectTo] => [[+gotopage]]" and the log also says "`[[+gotopage]]` is not a valid integer and may not be passed to makeUrl()"

          Must be some PHP thing I'm not getting. It all looks a simple thing to but I can't get it to return a value to redirectTo
            David Heriot
            pfsmedia
            • 9439
            • 90 Posts
            Hmmm. So Formit accepts other values from the custom hook, but *not* redirect. Here's the snippet now (as simple as I can make it)
            $datestamp = date('Y-m-d H:i:s');
            $nextpage = $hook->getValue('number-required');
            $recipient = $hook->getValue('email');
            $hook->setValue('datestamp_submitted', $datestamp);
            $hook->setValue('email_address', $recipient);
            $hook->setValue('gotopage', $nextpage);
            $modx->log(modX::LOG_LEVEL_ERROR, 'pageid is: '.print_r($nextpage,true));
            return true;

            Formit:
            [[!FormIt?
            &hooks=`altRedirect,email,redirect`
            &validate=`number-required:required:minLength=`1``
            &store=`1` 
            &emailTpl=`emailTpl` 	
            &emailTo=`[[+email_address]]` 	
            &emailSubject=`Test Form`
            &redirectTo=`[[+gotopage]]`
            &submitVar=`go`
            ]]

            Email Tpl:
            <p>Hello [[+firstname]]</p>
            Page: [[+gotopage]]<br />
            Email: [[+email_address]]<br />
            Phone: [[+telephone]]<br />
            Day: [[+datestamp_submitted]]


            The email is duly sent to [[+email_address]] and in the email, [[+gotopage]] is replaced by an integer. But the form refuses to redirect to this integer because, in the log, it says, again, "..`[[+gotopage]]` is not a valid integer and may not be passed to makeUrl()"

            Why not? Why isn't +gotopage an integer when it returns to Formit? I confess I have no earthly idea. Can someone point to the error in my code?
              David Heriot
              pfsmedia