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

    I’m just wondering if there’s anyone out there who has any idea on how to send the user to different thank you pages depending on certain data input into the form. For example, if the user puts in a certain "discount code" into the discount code field, they would be taken to a thank you page that has info specific to that discount code.

    Any help is much appreciated. Thanks!!!
      • 30223
      • 1,010 Posts
      Use the onMailSent event and do something like this:

      //<?php
      function onMailSentEvent(&$fields){
         global $modx;
         switch($fields['discount_code']){
            case 'code1': 
               $id = 73;
               break;
            case 'code2': 
               $id = 74;
               break;
            case 'code3': 
               $id = 75;
               break;
            default:
               $id = 70;
         }
         $modx->sendRedirect($modx->makeUrl($id));
      }
      


      Of course you need to make sure that the ids actually refer to real document ids ):
        • 41824
        • 19 Posts
        Thank you for your reply! (As always, so quick! smiley

        Does this eliminate the need for the &goto or &thankyou parameters in the eForm call?

        I’m assuming this code:
        $modx->sendRedirect($modx->makeUrl($id));

        does a redirect directly from the function onMailSentEvent?

        Thanks again!
          • 30223
          • 1,010 Posts
          Yep, this overrides the gotoid and thankyou parameter.


            • 41824
            • 19 Posts
            I hate to bug you, but I’ve been testing this and for some reason it’s not working out. The e-mail is still being sent ok, but the page stays on the same id as the form, but goes blank. I have to type in a different id, then go back to that page just to get the form to show up again. If I keep refreshing while it’s blank, it says that the data has already been sent. Here’s what I have so far:

            The page call:
            [[thankYouRedirect]]
            [!eForm? &formid=`RegForm` &subject=`[+subject+]` &to=`[email protected]` &from=`[email protected]` &fromname=`Webmaster` &replyto=`[+email+]` &ccsender=`0` &tpl=`RegForm` &report=`RegFormReport` &invalidClass=`invalidValue` &requiredClass=`requiredValue` &cssStyle=`ContactStyles` &eformOnMailSent=`onMailSentEvent` !]


            The snippet "thankYouRedirect":
            <?php
            function onMailSentEvent(&$fields){
               global $modx;
               switch($fields['code']){
                  case 'code1': 
                     $id = 71;
                     break;
                  case 'code2': 
                     $id = 74;
                     break;
                  case 'code3': 
                     $id = 79;
                     break;
                  default:
                     $id = 80;
               }
               $modx->sendRedirect($modx->makeUrl($id, '', '', 'full'));
            ?>


            The input from the form:
            <input name="code" id="cfCode" class="text" type="text" />


            I’ve thought it was a syntax error (which it still might be), so I’ve been combing over this for an hour trying to eliminate that option. The process makes sense to me, but perhaps I’m still making a stupid mistake someplace. Any help is greatly appreciated! Thank you so much!
              • 30223
              • 1,010 Posts
              it should be &eFormOnMailSent=`onMailSentEvent` not &eformOnMailSent=`onMailSentEvent`
                • 41824
                • 19 Posts
                Thanks! I tried that and it wasn’t working still, so I peeled over it with a fresh set of well rested eyes and found that I didn’t have a closing curly brace to close out the function! I knew it was something stupid! It works great. I greatly appreciate your help and quick responses. You sir, rock.