We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9439
    • 90 Posts
    I want to output an integer from a snippet but I can't get it to work. So I reduced the snippet to something simple, and it still doesn't work
    $nextpage = 45;
    $output = $modx->getChunk('test_chunk', array(
            'gotopage' => $nextpage,
        ));
    return true;


    In the chunk there's only
    [[+gotopage]]
    When I use the chunk, <p>test chunk is [[$test_chunk]]</p>, it's blank, ie it returns, test chunk is

    What am I doing wrong?
      David Heriot
      pfsmedia
      • 3749
      • 24,544 Posts
      return $output;
      wink
        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
        • 9439
        • 90 Posts
        Thanks Bob. Now I know I'm not explaining this properly, as the reason I had
        return true;
        is that the snippet is a custom hook and they need to return true. If you'd known it was a hook you'd have given a different answer.

        All I'm trying to do is use a custom hook to return a form value for Formit redirectTo. Since I've tried everything I can think of I thought maybe I need to output to a chunk, then maybe multiply by 1 to turn it into an integer then use the chunk as the redirectTo value. But nothing I try works - they all end up as an error "`[[...]]` is not a valid integer and may not be passed to makeUrl()"

        Any help welcome.


          David Heriot
          pfsmedia
          • 3749
          • 24,544 Posts
          Ah, then put this just above the return:

          $modx->setPlaceholder('gotopage', $output);
            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
            • 9439
            • 90 Posts
            Well, that works nicely, thank you, but here's the crux of the matter. Why can't formit's redirectTo also use [[+gotopage]]? The number's in the placeholder, the chunk is displaying the placeholder, the email is displaying the placeholder, but redirectTo stubbornly refuses.
            `[[+gotopage]]` is not a valid integer and may not be passed to makeUrl()
            

            I noticed another long thread about roughly the same issue with redirectparams. Is it not possible to use a placeholder for redirectTo?

              David Heriot
              pfsmedia
              • 3749
              • 24,544 Posts
              It ought to be possible, but the snippet that sets the placeholder would have to be above the FormIt tag.
                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
                • 9439
                • 90 Posts
                I don't see how that could work though, as the value of redirectTo comes from a form value:
                $nextpage = $hook->getValue('number-required');
                ie redirect page varies with number-required.
                  David Heriot
                  pfsmedia
                  • 9439
                  • 90 Posts
                  In any case, if &emailTo can use the output from a form field, and the email hook is processed by Formit before the redirect hook, why can't &redirectTo also use the output of a form field?
                    David Heriot
                    pfsmedia
                    • 3749
                    • 24,544 Posts
                    Try making your snippet that sets the placeholder the first hook in the list. I don't think it will work, but it's worth a try. If it doesn't, this should definitely work.

                    Leave out the redirect hook and make your own MyRedirect hook (something like this) and put it last in the list:

                    /* MyRedirect snippet */
                    $redirectParams = array(  // array of URL params
                        'param1Name' => 'param1Value',
                        'param2Name' => 'param2Value',
                         // etc.
                    );
                    $url = $this->modx->makeUrl($_POST['number-required'],'web',$redirectParams,'full');
                    $modx->sendRedirect($url);
                    return true;
                    


                    If there are no params, you can do it like this:

                    $url = $this->modx->makeUrl($_POST['number-required'],'web',"",'full');



                      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
                      • 9439
                      • 90 Posts
                      Thanks for that Bob, but I'd already tried using
                      $modx->sendRedirect($url);
                      I just used makeurl with the 'number-required' value and it worked fine. The problem was that on the receiving form, there were no stored values for Formretriever. Switched back to redirectTo, previous form values are retrieved, switched to sendRedirect, values aren't stored. Looked like Formretriever relied on the redirect hook to work. Is there such a coupling?
                        David Heriot
                        pfsmedia