We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29774
    • 386 Posts
    Is it possible for eform to be set up to validate form elements that are injected into the DOM by javascript? I’m guessing I’d need to amend the form template chunk on the fly using an eform event, or a custom snippet that runs eform using $modx-runSnippet() ?

    This is the kind fo thing I need to achieve:

    <!--hardcoded markup-->
    <input name="name1" id="name1" type="text" value="[+name1+]" eform="Name1::1:"/>
    
    <!--injected markup-->
    <input name="name2" id="name2" type="text" value="[+name2+]" eform="Name2::0:"/>
    


    The injected markup would always be a copy of an existing section of hardcoded markup, but with an incrementing trailing index, eg name1, name2, name3.

    Going on from the initial validation of this data, I also want to be able to store the data in a database and then retrieve it and repopulate the form. And I should also mention that this would be a multi-page form with a branching.

    Is eform the best tool for this or should I write a custom class? If so, can anyone point me to a super flexible form handling library that works nicely with modx? If anyone has ever done anything like this I’d love to hear the details.

    Thanks!

    Mark
      Snippets: GoogleMap | FileDetails | Related Plugin: SSL
      • 20413
      • 2,877 Posts
      I know nothing but I read this in the wiki:

      Hidden fields
      By default hidden fields are validated as a protection against tampering by comparing the input against the value set in the form template (much like the select, checkbox and radio fields) In some circumstances this may not be desirable however. For instance when you use some javascript in your form to store a result in a hidden field. In those cases you can turn this behaviour off by setting the eform attribute (with or without it’s own validation).

      This is another way of form validation ---> http://modxcms.com/forums/index.php/topic,30540.msg185573.html#msg185573

        @hawproductions | http://mrhaw.com/

        Infograph: MODX Advanced Install in 7 steps:
        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
        • 29774
        • 386 Posts

        This is another way of form validation ---> http://modxcms.com/forums/index.php/topic,30540.msg185573.html#msg185573

        Thanks mate, but unfortunately that’s the kind of thing I wanted to avoid - manually validating form elements - I’ve got *hundreds* of fields! I was hoping eform could do the heavy lifting...
          Snippets: GoogleMap | FileDetails | Related Plugin: SSL
          • 20413
          • 2,877 Posts
          Maybe ---> http://modxcms.com/forums/index.php/topic,27794.0.html  smiley

          //will stop spamming your post and leave it to someone who knows stuff tongue
            @hawproductions | http://mrhaw.com/

            Infograph: MODX Advanced Install in 7 steps:
            http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

            Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
            http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
            • 33372
            • 1,611 Posts
            I think that you’d have to use an eForm event function to validate these fields separately, since the eform tag is processed when the form is first parsed afaik (if your function passes error messages to the eForm validation or required variable it will display them as usual). Could you make your injected variables into arrays? That would make looping through them in a function easier (although you could loop through the $_POST array and process any that begin with "Name", etc.).
              "Things are not what they appear to be; nor are they otherwise." - Buddha

              "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

              Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
              • 29774
              • 386 Posts
              @ZAP

              Yes the injected content could use array notation for the field names - great idea smiley

              I’m wondering if eform would process these extra values despite them being injected, if the hardcoded template contains the first field with name="myFields[]" ? Since this would tell eform to treat the value as an array, and it presumably parses the entire $_POST array on each validation pass so it should pick up any extra values in the ’myFields’ array.

              When it comes to pre-populating eform with data (from a serialised object stored in a session or from a db), I think the idea of sending eform a customised template chunk could work (ie use a snippet to load the default chunk and then insert the extra fields into the markup) - although there would be some question over what happens if someone decided to then delete the additional form fields (using javascript) - would eform choke if an expected field was completely missing from $_POST?

              Time for some experimenting I think. Thanks for your help guys.
                Snippets: GoogleMap | FileDetails | Related Plugin: SSL
                • 33372
                • 1,611 Posts
                I have been able to prepopulate eForms and process fields that were not present in the original form chunk using eForm event functions. There are several examples in the MODx wiki that you might find helpful. If you push a value into the eForm fields or validation or required errors array from an event fuction, eForm will continue the process as if those values had come to it by the normal method.
                  "Things are not what they appear to be; nor are they otherwise." - Buddha

                  "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                  Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options