We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18274
    • 2 Posts
    Hello All --

    So I am an absolute beginner in all things MODx, just trying to understand the logic of how chunks and snippets and things come together.

    I am trying to build my first form, heavily relying on the example from /assets/snippets/eform/docs/eform_examples.htm

    I have following issues:


    • The name field is tested for two words, using a regex defined like this:#REGEX /\w+\b\w{2,}/i. I am not a pro when it comes to regular expressions, but it looks sort of ok. Just doesn’t seem to work, though, however many words I have I get a validation error message.
    • what exactly do these eform="..." attributes do in the form chunk? I see things like ’eform="Your Email Address:email:1"’ and have not found any documentation on what this does. I can see it must somehow be related to input sanitation/validation, but how does it work?
    • At last, the validation errors turn up in english - how can I replace them with messages in another language?

    I presume it’s me being dumb, but I’m stuck, and I’d be very grateful if somebody could give me a hint or two.

    Thanks in advance,
    Marc
      • 30223
      • 1,010 Posts
      The regular expression in the example is wrong. Try this instead
      /\w+\s\w{2,}/i

      If that doesn’t work, try it with double backslashes i.e.
      /\\w+\\s\\w{2,}/i


      The eform attributes are described in the documentation under the heading "Datatypes and formatting" in eform/docs/eform.htm. Here’s waht it says:

      Datatypes and formatting
      eForm is incorporating a form parser which extracts formatting and validation options from each form field. To set options for a field add the eform (pseudo) attribute to each required form field.

      <input type="text" name="color" eform="A Color:string:1" />


      The basic format of the eform attribute is:
      [description/title]:[datatype]:[required]:[validation message]:[validation rule]

      Default validation (and other) messages are set in a language files which you can find in the eform/lang/ directory. At the moment only the english language file is distributed with eform. You can easily create a new language file and use that by adding the ’&language’ parameter to the snippet call - for instance if you created a spanish.inc.php langage file you would add:
      [!eForm? &language=`spanish` ...!]


      What language are you after?

      Hope this helps..
        • 18274
        • 2 Posts
        TobyL --

        Thanks for your help. My form works now - indeed the regex was wrong (and I had \b in the back of my mind as ’blank’). Sorry for not finding the documentation.

        I need the validation messages in german and french. Took the liberty to translate into german already, the file’s attached if somebody needs it. The debug messages may have lost poetic quality in translation, the user facing messages are all quite understandable german.

        I’ll do french as well in the next days.

        Thanks,
        Marc