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

    Is there a way to do a dynamic redirect? I have the following which I assumed would work but can't get it to work. The form is submitted and the email is being sent but the redirect isn't working.
    [[!FormIt?
    &hooks=`spam,email,redirect`
    &emailTpl=`MyEmailChunk`
    &emailTo=`***@***.com`
    &emailFrom=`***@***.co.uk`
    &emailFromName=`*** Website`
    &emailSubject=`*** Website Request`
    &redirectTo=`[[+redirectTo]]`
    ]]


    <form action="[[~[[*id]]]]" method="post">
    	<input type="hidden" name="nospam" value="" />
    		<input type="text" name="name" id="name" value="[[!+fi.name]]" placeholder="Name">
    		<input type="text" name="email" id="email" value="[[!+fi.email]]" placeholder="Email">
    		<input type="text" name="telephone" id="telephone" value="[[!+fi.telephone]]" placeholder="Telephone">
    		<input type="text" name="address" id="address" value="[[!+fi.address]]" placeholder="Address">
    		<input type="text" name="company" id="company" value="[[!+fi.company]]" placeholder="Company">
    		<input type="text" name="job-title" id="job-title" value="[[!+fi.job-title]]" placeholder="Job Title">
    
    		<select name="redirectTo">
    			<option value="3" [[!+fi.redirectTo:FormItIsSelected=`3`]]>Download PDF</option>
    			<option value="2" [[!+fi.redirectTo:FormItIsSelected=`2`]]>Send Catalogue </option>
    		</select>
    
    	<input type="submit" value="Request">
    </form>
    

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

      ■ email: [email protected] | ■ 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.
      • 30585
      • 833 Posts
      How are you setting the content of [[+redirectTo]] placeholder?
        A MODx Fanatic
        • 17301
        • 932 Posts
        I was hoping to set it from the user select in the form. The same way that dynamic email to works.
          ■ email: [email protected] | ■ 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.
        • discuss.answer
          • 51272
          • 7 Posts
          Joeke Kloosterman Reply #4, 7 years ago
          The best way to accomplish this is with a custom hook. Set the redirectTo parameter in the FormIt to some default value, and let the hook set it when submitting the form:
          [[!FormIt?
          &hooks=`spam,email,setRedirectTo,redirect`
          &emailTpl=`MyEmailChunk`
          &emailTo=`***@***.com`
          &emailFrom=`***@***.co.uk`
          &emailFromName=`*** Website`
          &emailSubject=`*** Website Request`
          &redirectTo=`123`
          ]]
          


          And in your setRedirectTo snippet:
          <?php
          $formit =& $hook->formit;
          $values = $hook->getValues();
          $redirectTo = $values['redirectTo'];
          if ($redirectTo && is_numeric($redirectTo)) {
              $formit->config['redirectTo'] = $redirectTo;
          }
          return true;
          
            • 17301
            • 932 Posts
            Cool, Thanks Joeke! I'll give it a try and report back shortly.
              ■ email: [email protected] | ■ 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.
              • 17301
              • 932 Posts
              Worked perfectly, thank you.
                ■ email: [email protected] | ■ 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.