We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34120
    • 236 Posts
    I’ve got a generic validation message working for my required form fields. The problem is the email validation also returns a ’required’ error message, so i get 2 messages. I only want the email to trigger an error if the address is invalid, is this possible?

    [[!FormIt?
      &hooks=`spam,email`
      &validate=`name:required,email:email:required`    
    ]]
    
    [[!+fi.validation_error_message:notempty=`Please complete the required fields`]]
    [[!+fi.error.email]]
      • 34120
      • 236 Posts
      I’ve got a work around so that will have to do, I’ve got another problem now though with checkboxes.
      <input type="checkbox" name="int01" id="int01" value="1" [[+fi.int01:notempty=`checked="checked"`]] />
      <input type="checkbox" name="int02" id="int02" value="1" [[+fi.int02:notempty=`checked="checked"`]] />

      [[+int01:if=`[[+int01]]`:eq=`1`:then=`INT 01 Selected<br/>`:else=``]]
      [[+int02:if=`[[+int02]]`:eq=`1`:then=`INT 02 Selected<br/>`:else=``]]

      This works fine if the checkboxes are selected but if non are selected then the formit code above is output in the email.

      Any ideas anyone?
      Thanks
        • 6228
        • 249 Posts
        Have you tried:
        [[+int01:notempty=`INT 01 Selected<br/>`]]
        [[+int02:notempty=`INT 02 Selected<br/>`]]

        or..
        [[!+int01:notempty=`INT 01 Selected<br/>`]]
        [[!+int02:notempty=`INT 02 Selected<br/>`]]
          lo9on.com

          MODx Evolution/Revolution | Remote Desktop Training | Development
          • 34120
          • 236 Posts
          I’ve been off this for a while but your post works cyclissmo, many thanks!
            • 34120
            • 236 Posts
            Just bumping to see if anyone has any ideas on the initial post, thanks

            Quote from: rf9 at Jul 01, 2011, 03:33 PM

            I’ve got a generic validation message working for my required form fields. The problem is the email validation also returns a ’required’ error message, so i get 2 messages. I only want the email to trigger an error if the address is invalid, is this possible?

            [[!FormIt?
              &hooks=`spam,email`
              &validate=`name:required,email:email:required`    
            ]]
            
            [[!+fi.validation_error_message:notempty=`Please complete the required fields`]]
            [[!+fi.error.email]]

              • 6228
              • 249 Posts
              You can always just remove the [tt]:required[/tt] validator from the email field, but that will allow empty emails to pass. I don’t think you want that.

              AFAIK the proper way to approach this is to create a snippet to validate the email according to your criteria, and then register it as a custom validator.

              The only other alternative that I can think of is commenting out the first statement in the [tt]email()[/tt] method in [tt]fivalidator.class.php[/tt]. That should stop empty emails from passing through the [tt]:email[/tt] validator. Only problems is, that change will ’undo’ when you update the package.
                lo9on.com

                MODx Evolution/Revolution | Remote Desktop Training | Development
                • 34120
                • 236 Posts
                Thanks again cyclissmo, yeah I briefly looked at using a custom validator. I guess the snippet would contain some kind of regex to validate the email. I did have a look at the fivalidator.class.php to see if I could use the code from there but it seems like a lot of work for a small non critical feature. Maybe when I get some time I can take a look.

                Thanks for the help.