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

    I have an e-mail form which returns to the same page after sending.
    I want to give the user a confirmation. Something basic, like "Your message has been send!" above the form.

    I think I need to use hooks... but how? Can anybody help me? Thanks!
      • 3749
      • 24,544 Posts
      Could you use the &redirectTo parameter to send the user to another page that showed the success message?

      &redirectTo=`success/page/url`


        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
        • 14730
        • 34 Posts
        I could, but I rather learn how to use hooks.
        There’s more forms to be build!
          • 3749
          • 24,544 Posts
          Hooks are really simple. You just put the name of your snippet in the &hooks parameter. Have your snippet set a placeholder with the success message and return true;

          In the FormIt tag:
          &hooks=`email,MySnippet`


          The snippet:
          <?php
          /* MySnippet */
          $modx->setPlaceholder('fi.success','Your email has been sent');
          return true;
          ?>


          On the page where you want the success message to appear:

          [[+fi.success]]
            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
            • 14730
            • 34 Posts
            Awesome, just what I need! Thanks man!
              • 14730
              • 34 Posts
              Bit too early with my props...

              Something is working, but the only output I get (on a successful send) is:
              1

              I did what you said.
              - [[+fi.success]] on the page
              - my hooks:
              &hooks=`recaptcha,email,success_message`

              - the snippet (named success_message):
              <?php
              $modx->setPlaceholder('fi.success','Your email has been sent.');
              return true;
              ?>


              I use MODx Revolution 2.0.0-pl rev7212

              Any idea what went wrong here? Thanks!
                • 36926
                • 701 Posts
                Hey Jorik,

                You could also use this:
                    [[+fi.success:if=`[[+fi.success]]`:eq=`1`:then=`Thanks you`]]
                


                Just place this within the page where you want the message to appear.

                  • 3749
                  • 24,544 Posts
                  Be sure the placeholder is below the FormIt tag.

                  Try changing the setPlaceholder line to:

                  $scriptProperties['hook']->fields['success'] = 'Your email has been sent.';
                  




                  If that doesn’t do it, (with my original code) try changing the name from fi.success in the placeholder tag and the snippet to something without an fi. prefix (e.g, ’SuccessMessage’). That way FormIt should leave it alone and it will be just a normal placeholder.
                    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
                    • 14730
                    • 34 Posts
                    RE:BennyB
                    Thanks for the suggestion. Bit of a workaround but would have worked.
                    I tried the other solutions, one worked!

                    RE:BobRay
                    After changing both lines, getting failures, I left FormIt alone. It worked! Thanks!

                    So, as a summary for all forum skimmers:

                    Create a Snippet "snippet_name"
                    <?php
                    $modx->setPlaceholder('placeholder','output_message');
                    return true;
                    ?>


                    Add the snippet as a hook in your FormIt tag:
                    &hooks=`email,snippet_name`


                    Place the placeholder below the FormIt tag:
                    [[+placeholder]]


                    If the email is evaluated as true, your "placeholder" will be replaced with your "output_message".

                    Have fun, and thanks to the two above,

                    Jorik
                      • 3749
                      • 24,544 Posts
                      I’m glad you got it working.

                      This *should* work also instead of your setPlaceholder line, and with a [[+fi.success]] tag below the FormIt tag, but I’ve only tested it with preHooks:
                      $scriptProperties['hook']->fields['success'] = 'Your email has been sent.';


                      I tested it with Modx 2.0.2 and FormIt 1.2.1, so YMMV if you use different versions.
                        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