We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17802
    • 190 Posts
    Is it possible to put the validation error message in a template chunk? I’d like to have an error class in my css to make this information stand out some more. Of course I could put a paragraph with class="error" in my template, but I don’t want this paragraph to be present when there’s no error message. (I hope I’m making myself clear)
    Thanks!
      Thanks for MODx - I love it!
    • If you look at the default templates that come with MODx (0.9.5, anyway) you’ll see the section for the error messages is included in the template chunk.
        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
      • The validation message really needs some additional template mojo though, to include a wrapper around the message. There’s no current way to make the validation message completely disappear when there’s no error/validation issue – unless you don’t want to wrap your error messages in anything (like a <div class="error">).

        This is problematic when you have an error message "block" on your page with a bg color and padding, but it’s empty... typically it’s bright red or yellow or some other such design to draw attention. You wind up with an empty colored block above your form.
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • I’d suggest adding something like the following to the existing language files:

          $_lang["ef_message_wrap"] = "<div class=\"errors\">[+wrapper+]</div>";


          Then outputting the actual error messages into the wrapper placeholder.
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 17802
            • 190 Posts
            Yes Ryan, that’s exactly what I meant to say. Thanks for your solution, I’m going to play with it and see if it works for me. smiley
              Thanks for MODx - I love it!
            • I looked quickly, but I couldn’t find where the error message was being returned. If you find it please post back. Thanks!
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 30223
                • 1,010 Posts
                Quote from: rthrash at Dec 08, 2006, 03:12 PM

                I looked quickly, but I couldn’t find where the error message was being returned. If you find it please post back. Thanks!

                existing line 255 - 258 (for 1.4.1a as distributed with modx 0.9.5)
                <?php
                # set validation error message
                $fields['validationmessage'] .= $_lang['ef_validation_message'];
                $fields['validationmessage'] .=(count($rMsg)>0)?str_replace("{fields}", implode(", ",$rMsg),$_lang['ef_required_message']):"";
                $fields['validationmessage'] .= implode("<br />",$vMsg);
                ?>
                


                If you change that code to something like this
                <?php
                #set validation message
                $tmp = (count($rMsg)>0)?str_replace("{fields}", implode(", ",$rMsg),$_lang['ef_required_message']):"";
                $tmp = implode("<br />",$vMsg);
                $fields['validationmessage'] .= str_replace('[+wrapper']', $tmp, $_lang['ef_validation_message']);
                ?>
                


                and change the existing $_lang[’ef_validation_message’] in the language file to something like this: (no need for an extra string in the language file)
                <?php
                $_lang['ef_validation_message'] = "<div class=\"errors\">[+wrapper+]</div>";
                ?>
                


                I think you’ll have what you need.
                • Hi TobyL and thanks!

                  Think you might incorporate this into an eForm update and we’ll get it in with the 0951 release that is being done to include additional languages (Russian, Dutch, Japanese)?
                    Ryan Thrash, MODX Co-Founder
                    Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                  • Toby,

                    A few minor things:

                    1) Minor syntax glitch: the [+wrapper’] in your revision above should be [+wrapper+]
                    2) Probably should really make it [+ef_wrapper+] to avoid potential namespace collisions
                    3) It’s not seeming to output any of the actual messages on my test install with the following code. The error box does not show until there’s an actual error condition though, so we’re half way there! (The original code does output the error messages; I reverted and double-checked.)

                    <?php 
                    $_lang["ef_validation_message"] = "<div class=\"errors\"><strong>Some errors were detected in your form:</strong><br />[+ef_wrapper+]</div>";
                    
                    # set validation message
                    $tmp = (count($rMsg)>0)? str_replace("{fields}", implode(", ",$rMsg),$_lang['ef_required_message']) : "";
                    $tmp = implode("<br />",$vMsg);
                    $fields['validationmessage'] .= str_replace('[+ef_wrapper+]', $tmp, $_lang['ef_validation_message']);
                    ?>
                    
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 30223
                      • 1,010 Posts
                      I didn’t actually test this myself I must admit,.. but I will now smiley

                      I’ll try to make some time to incorporate this into 1.4.2 which is still waiting to be put in the repository.

                      EDIT: No wonder it didn’t work as expected. I left out an important ’dot’... here’s the corrected code with the renamed placeholder

                      <?php 
                      $_lang["ef_validation_message"] = "<div class=\"errors\"><strong>Some errors were detected in your form:</strong><br />[+ef_wrapper+]</div>";
                      
                      # set validation message
                      $tmp = (count($rMsg)>0)? str_replace("{fields}", implode(", ",$rMsg),$_lang['ef_required_message']) : "";
                      // should be '.=' instead of just '='
                      $tmp .= implode("<br />",$vMsg);
                      $fields['validationmessage'] .= str_replace('[+ef_wrapper+]', $tmp, $_lang['ef_validation_message']);
                      ?>