We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20349 ☆ A M B ☆
    • 453 Posts
    Hi all MODxers laugh



    Does anyone have a working example of eForm in combination with jQuery validation?

    eFrom call and TPL’s would be nice wink


    Edit: something like this -> http://www.geektantra.com/projects/jquery-form-validate/advanced_demo/
      BASE - Web Design Studio
      MODX Ambassador

      Website
      • 7914
      • 137 Posts
      I have not worked with this specific method of validation, but I have used this before and it works very well.

      The js validation is going to be all client-side (as you probably know) so it’s somewhat independent of eForm. (At least that’s how I envision it)

      In the past I typically create a new template for my form since I will call in some extra js files. I do this only so on 9 of 10 pages I’m not making extra server requests. (The 10th page being the form)

      So, I would more than likely already be calling in jqery in a global js file. I will also need to call in the validation library.js file, and also my form-validation.js file. In that file I would set up my validation rules.

      In the link I provided, my template would look like:
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script>
      <script src="assets/js/libs/jquery.validationEngine-en.js"></script>
      <script src="assets/js/libs/jquery.validationEngine.js"></script>
      <script src="assets/js/my-form-validation.js">
      

      The top 3 calls are to the respective libraries.
      The bottom call would be to a page that I build. It would look something like:
      $(document).ready(function(){
      	// validation
      	$("#my-form-id").validationEngine();
      
      });
      // -- end DOM ready events -- //
      


      My html of the form is pretty straight forward.
      <label for="name">Name</label>
      <input type="text" id="name" name="name" maxlength="40" value="" class="validate[required, custom[noSpecialCaractersSpaceOk]]" />
      

      The "custom" is just a rule that I wrote to extend the existing "noSpecialCharacters" rule.

      Since the js will stop any form processing before the server validates, you can also incorporate eForm’s validation. It should play nicely together.

      Not sure I was much help but that is my experience.

        • 4310
        • 2,310 Posts
        I’ve used it on Gorman Darby
          • 20349 ☆ A M B ☆
          • 453 Posts
          Thanks dowhatnow!

          I will try it and if I include it sucesfully, will post a link wink
            BASE - Web Design Studio
            MODX Ambassador

            Website
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            eForm doesn’t care what kind of javascript you use. It doesn’t even see the fields until the form is finally submitted, and even then it doesn’t care if it’s been called via an AJAX request for a totally different resource.

            All you need to do is pick your preferred jquery validation library, and then create your chunk tpl for the form to suit. The eform attributes are stripped before the form is sent to the browser, so you don’t even have to worry about those in your form fields.

            As far as separate templates, eForm has parameters to set your jscript and css tags
            &cssStyle (optional)
            Adds a style declaration to the <head> section of the page when either the form is
            displayed or the thank you page is displayed (only if the &thankyou parameter is set).
            Values can be a document id (numeric), chunk name or (relative or absolute) url to css file.
            Multiple values can be separated by a comma (in fact all three values can be mixed).
            [!eForm &cssStyle=`assets/site/forms.css,chunkName` ... !]
            [!eForm &cssStyle=`chunkName` ... !]
            [!eForm &cssStyle=`http://mysite.com/assets/styles/forms.css` ... !]
            Chunks (and documents if a doc id is given) can return a values in the form of:
            1. an inline style block, eg. <style type="text/css">/some styles/</style>
            2. a link to stylesheet(s), eg. <link href="assets/site/forms.css" rel="stylesheet"
            type="text/css">
            3. a comma separated list of urls, eg. assets/site/forms.css,assets/site/more.css,assets/site/gone_overboard.css
            &jScript (optional) Similar to &cssStyle but for adding javascript to the <head> of the page document.
            Currently Javascript is only added when the form is displayed.
              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