We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33372
    • 1,611 Posts
    I was recently looking at the fancy client-side form validation by DHTML Goodies (http://dhtmlgoodies.com/scripts/dhtml-form-validation/dhtml-form-validation.html) and also thinking about extending eForm to validate credit card numbers and future expiration dates for ShopX. When I looked at their script it struck me that the same method could make eForm infinitely flexible by allowing people to add their own custom patterns for validation. This seems like it would be simpler than adding every possible desired form type into the script, and additionally it seems as if it would be a quick jump from there to reformatting the input to normalize it and make it more aesthetically-pleasing before sending the results.

    So for example, I might add something like this to the beginning of my eform snippet:

    customType['phone']['pattern'] = '^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?|\.?))[2-9]\d{2}[- \.]?\d{4}$;
    customType['phone']['output_mask'] = 'whatever the regex would be to format any matched pattern to (123) 456-7890 - I'm too lazy to do it now';
    customType['phone']['error_msg'] = ' does not appear to be a valid phone number. Please enter your complete phone number (including area code).';
    


    Then I could declare a field to be customType[’phone’] in my snippet call and it could be validated and reformatted as specified. So for example I could have a credit card number pattern match that would be specific to my needs (we take Visa, MC, and AmEx, but not Discover). And since the match pattern is set in the snippet itself you could have PHP-scripted patterns (for example, any future date).

    Does that seem like it could be a useful way of extending eForm’s functionality in terms of validation?
      "Things are not what they appear to be; nor are they otherwise." - Buddha

      "Well, gee, Buddha - that wasn't very helpful..." - ZAP

      Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
    • As expected, I really like the idea. smiley
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 33372
        • 1,611 Posts
        ...ahem... embarrassed

        Now that I’m actually READING the documentation that comes with the latest eForm, it seems to me as if I can probably already do everything I mention above with the current features (between #REGEX and #FILTER and events)...

        So I’m going to try to do that and I’ll leave you to decide whether the method I mention may or may not be a helpful addition or whether I shoulda read the documentation before opening my trap...
          "Things are not what they appear to be; nor are they otherwise." - Buddha

          "Well, gee, Buddha - that wasn't very helpful..." - ZAP

          Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
          • 32963
          • 1,732 Posts
          Hi Zap,

          Yes youn can use #REGEX to make custom validation matching but I like the idea of output masking. In eForm 2.0 I’m planning on adding similar features that will allow you to add custom validators and a few other things. Not only will you be able to validate strings but you will also be able to validate images as well.
            xWisdom
            www.xwisdomhtml.com
            The fear of the Lord is the beginning of wisdom:
            MODx Co-Founder - Create and do more with less.