Subscribe: RSS
  • I have a formalicious form that I want to have a different redirect depending on the context where I put the form. When I set it up like this:

    &redirectTo=[[++membership_renewal_resource]]

    it doesn't actually work. Is there a different way to achieve this?

    This question has been answered by aarond. See the first response.

    • Have you tried calling it uncached? Verify it's posting the correct value by placing it in the body so you can see its output too.
        ■ email: lk@alienbuild.uk | ■ 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.
      • Quote from: lkfranklin at Feb 01, 2018, 07:23 PM
        Have you tried calling it uncached? Verify it's posting the correct value by placing it in the body so you can see its output too.

        I put the [[++membership_renewal_resource]] in an html content block on the page where my form is, so that it can be seen, and yes it is parsing the number properly. It seems as if the redirectTo parameter isn't parsing the context variable.
        • If you're seeing the number in the source, it's definitely reading the context setting. Since it's just a number, I don't think it's a parsing issue.

          I couldn't find any docs for the redirectTo property. I'm guessing it's not redirectTo. I'd look at the formalicious code in core/components/formalicious/elements, or more likely, core/components/formalicious/model to see the actual property name used in the getOption() call. It will be case-sensitive.
            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
          • Quote from: BobRay at Feb 01, 2018, 08:00 PM
            If you're seeing the number in the source, it's definitely reading the context setting. Since it's just a number, I don't think it's a parsing issue.

            I couldn't find any docs for the redirectTo property. I'm guessing it's not redirectTo. I'd look at the formalicious code in core/components/formalicious/elements, or more likely, core/components/formalicious/model to see the actual property name used in the getOption() call. It will be case-sensitive.

            I'm not the greatest at coding. I think this issue could be solved with a custom pre-hook maybe. I am not 100% sure on the syntax, but would a custom prehook called, say, setRedirectID work with the following pseudocode?

            Set $redirectTo [[++membership_renewal_resource]].

            This way I think it would set the redirect to before it generates the form on the page, whereas right now, it might just be taking [[++membership_renewal_resource]] and putting that in as a string, rather than converting it to the ID in the context variable.
            • Before you go down that route is it working with any redirect id? Are your hooks in the correct order?
                ■ email: lk@alienbuild.uk | ■ 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.
              • LK's questions are good -- maybe the page you're redirecting to is unpublished or protected by an ACL entry. Also, keep in mind that if there's a problem in any of the previous hooks, later ones won't execute at all.

                I would think you'd want a hook, rather than a preHook.

                The hook could look something like this, which gets the redirect ID directly from the Context Setting:

                $id = (int) $modx->getOption('membership_renewal_resource');
                $url = $modx->makeURL($id, 'web', "", 'full');
                $modx->sendRedirect($url);
                return;
                  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
                • discuss.answer
                  Thanks for the input guys. Gonna paste what I got working for me here for this prehook. Note that it is a prehook because in the Formalicious GUI there is no setting for hooks, only pre- and post-hooks.

                  <?php
                  $redirectID = $modx->context->getOption('membership_renewal_resource', null, '1');
                  $formit->config['redirectTo'] = $redirectID;
                  return true;
                  
                  • In that case, I think you want a postHook. Otherwise, the redirect may happen before the form is even displayed.
                      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
                    • Quote from: BobRay at Feb 01, 2018, 09:04 PM
                      In that case, I think you want a postHook. Otherwise, the redirect may happen before the form is even displayed.

                      My pre-hook isn't telling the form to submit though, its just setting the variable for when the form is submitted. I have tested this and it works good. I think a postHook would run into the same issue, in that the formalicious GUI can't set the resourceID from a context variable during/after the form renders.