We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5357
    • 30 Posts
    Is there a way to ’redirect’ the form so that a success note is simply output on the same page, rather than having to create a new resource that displays a message?

    Obviously you could spec the same resource ID for redirectTo and there’s already provision for an error message but not success, so it seems a long winded way to confirm the form has been successfully sent.
      • 3749
      • 24,544 Posts
      Your page contains the form (as plain HTML), so the user is going to see the form again if you do that. I think it would work if you specified the same page as the success redirect and added the appropriate placeholders to the page, but the form would still be there.

      It might be possible to hide the form with some fancy PHX-style output modifiers, but I’ve never tried it.

      Maybe someone else has a better idea.
        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
        • 5340
        • 1,624 Posts
        You could set up a hook that will set a Session Variable and when the page loads after submit read the session variable, display the message and reset the variable.
          • 5340
          • 1,624 Posts
          Quote from: cipa at Aug 25, 2010, 10:08 PM


          Is there a way to ’redirect’ the form so that a success note is simply output on the same page, rather than having to create a new resource that displays a message?

          Obviously you could spec the same resource ID for redirectTo and there’s already provision for an error message but not success, so it seems a long winded way to confirm the form has been successfully sent.

          You could set up a hook that will set a Session Variable and when the page loads after submit read the session variable, display the message and reset the variable.
          Anyway I think that redirecting is the proper way. In my case, on 99% of the forms I have some introductory text that can be edited by the admin in the content area. On submit the text be replaced by the thank you message.
            • 3749
            • 24,544 Posts
            Couldn’t you just add a placeholder where you want the success message and have your hook set its value with $modx->setPlaceholder()? If the hook comes after the email hook, it shouldn’t execute and the placeholder should be empty until the email hook is successful. (The last time I checked, failure of a hook didn’t keep the rest of the hooks from executing, but I’m fairly certain that’s fixed now).

              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
              • 25357
              • 92 Posts
              I have this working, sorta, but I’m stuck in one of those designer situations that forces me against my will to not have labels on the forms but use the form fields themselves as a label. I know, it’s insane . . . . I’m hoping they’ll see how stupid this is in testing (I have <label>’s, they are hidden.) This also interferes with any error messages used in the form fields.

              For whatever reason I cannot get the prehooks to work. Shortened, snippet loadInitialValues, pretty much from the manual,

              <?php
              $scriptProperties[’preHooks’]->fields[’fname’] = ’Your First Name’;
              $scriptProperties[’preHooks’]->fields[’email’] = ’Your Email Address’;
              return true;
              ?>

              (I have tried both preHook and preHooks)

              and the variations I’ve tried,

              [[!FormIt? &preHooks=`loadInitialValues` &hooks=`email,redirect` &emailSubject=`Visitor Inquiry from Your Site` &emailTpl=`smallFormReport` &emailTo=`[email protected]` &redirectTo=`43`]]

              [[!FormIt? &hooks=`loadInitialValues,email,redirect` &emailSubject=`Visitor Inquiry from Your Site` &emailTpl=`smallFormReport` &emailTo=`[email protected]` &redirectTo=`43`]]

              Even with the prehook by itself.

              [[!FormIt? &preHooks=`loadInitialValues`]]


              [[!FormIt? &hooks=`loadInitialValues`]]

              Typical field,

              <p><label for="emailaddr">Email Address:</label><span class="required">*</span> <input class="txt" type="text" id="emailaddr" name="emailaddr:email:required:stripTags" size="35" value=""></p>

              or with a value in it . . . doesn’t seem to do anything.

              I also can’t get the error message to display on intentional input errors, such as "sdsadfs" for the previous field. It’s identical to the sample in the manual:

              <p>[[+fi.error.error_message]]</p>

              and appears to "work" as its bouncing back to the form, it’s just the error message is null.



                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Usually this is done with javascript; onload the javascript will insert the value, then focus or some similar javascript event the field is cleared.

                http://www.joesak.com/2008/11/19/a-jquery-function-to-auto-fill-input-fields-and-clear-them-on-click/
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 3749
                  • 24,544 Posts
                  This worked for me with FormIt -- not as a preHook, but just as a snippet placed earlier on the page:

                  $isAuthenticated = $modx->user->hasSessionContext($modx->context->get('key'));
                  if (!$isAuthenticated) {
                      $modx->sendUnauthorizedPage();
                  }
                  $profile = $modx->user->getOne('Profile');
                  $name =  $modx->user->get('username');
                  $email = $profile->get('email');
                  $modx->setPlaceholder('fi.name',$name);
                  $modx->setPlaceholder('fi.email',$email);
                  return '';
                  


                  BTW, is your FormIt up-to-date? &preHooks is a recent addition.
                    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
                    • 25357
                    • 92 Posts
                    <oops> Sorry, I came upon this thread in a search. Yes, I have 1.21 installed, I didn’t see any input in the 1.2.1 thread.

                    I’ll give this a shot, thank you, still don’t understand why my error placeholder is null. Maybe it’s my hook. huh

                    EDIT: Just set up a test page exactly duplicating the example, this placeholder is coming up null here too:

                    <p>[[+fi.error.error_message]]</p>

                    EDIT 2: Oh . . I think I get it. Looked over the snippet again, this error is a placeholder if formit has a general error; can’t find an include, can’t mail, etc . . . . is that correct? I can see the errors in the sample by the fields. While I’m sure the "designer" would prefer to have any validation errors in one place I think I know what to do . . . move the field specific errors where I need them.