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

    Is there any maxlength validation builtin eForm? I tried to find in the docs, but it seems its not supported.

    Can it be possible to have this feature in eForm ? wink

    thanks and best regards.

    zi
      Zaigham R - MODX Professional | Skype | Email | Twitter

      Digging the interwebs for #MODX gems and bringing it to you. modx.link
      • 30223
      • 1,010 Posts
      Nah, it’s not in eForm at the moment. It has been relying on the browsers behaviour for that, but it’s probably not a bad idea to add this.

      How I’ll probably do it is to add that possibility to the text and textarea fields. eForm would ’read’ it directly from the input tags so in your form you would have something like this.

      <input type='text'  name='name' maxlength='15' value="" />
      <textarea name='textarea' maxlength='12000'>blah blah</textarea>
      


      I’d be inclined to simply truncate any input that’s too long and not necessarily generate an error. What do you think?

      (Oh and for those worried about xhtml validation,... the maxlength attribute would be stripped for the textarea before the form is displayed)
        • 33337
        • 3,975 Posts
        I would like to generate an error if <textarea> contains more than allowed characters/words. There should be a way to tell the site visitor that his/her information is too much.
        Only <textarea> is which does not has maxlength attribute, unfortunately (AFAIK).

        I tried to utilize javascript to control it, but when a user paste the information from clipboard, it just failed, some javascript strip out them on next mouse-click, some just leave it as it is (quickly tested), even if javascript works right, it will fail in case user has javascript turned off.

        So server side validation via php is a best and only solution to catch it IMO.
          Zaigham R - MODX Professional | Skype | Email | Twitter

          Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • Use a #FUNCTION validation rule or maybe even a #REGEX rule.

          #FUNCTION checkLen


          And something might be made of this, although regular expressions give me the willies...

          There are three other metacharacters that may be of use. The first is the braces metacharacter. This metacharacter follows a normal character and contains two number separated by a comma (,) and surrounded by braces ({}). It is like the star metacharacter, except the length of the string it matches must be within the minimum and maximum length specified by the two numbers in braces. Thus,

          ab{3,5}c

          will match "abbbc", "abbbbc" or "abbbbbc". No other string is matched. Likewise,

          .{3,5}pentane

          will match "cyclopentane", "isopentane" or "neopentane", but not "n-pentane", since "n-" is only two characters long.
            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