We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36541
    • 222 Posts
    I need to change the target for redirect hook based on certain conditions from another hook. I call FormIt with this:

    [[!FormIt?
    &hooks=`myHook,redirect`
    &redirectTo=`149`
    &store=`1`
    ...
    


    In [tt]myHook[/tt] I use this to change the [tt]&redirectTo[/tt] value:

    $hook->formit->config['redirectTo'] = 148


    This actually works and redirects to resource 148 instead of 149. What is essential here, the redirect can’t be invoked from inside the hook to not disturb the form submission and saving values to cache. Is this how it should be done or is there a more proper way to do it? I’m using FormIt 1.7.
      This is the web: the only thing you know about who will come is that you don't know who will come.
      • 11927
      • 105 Posts
      Wow, thank you for sharing this. I have been trying to do something like this for a month or two.
        You may or may not want to use the code I write. It's probably all against the syntax rules of php and MODx. smiley

        Carpet Cleaning
        • 36541
        • 222 Posts
        You're welcome smiley
          This is the web: the only thing you know about who will come is that you don't know who will come.
          • 28215
          • 4,149 Posts
          In FormIt 2.0+, this *should* work as well:

          $hook->setRedirectUrl('myurltogoto');
          
          /* or */
          
          $myResourceId = 123;
          $url = $modx->makeUrl($myResourceId,'','','full'); 
          // make sure to use 'full' above for IE
          $hook->setRedirectUrl($url);
          
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com