Jul 05, 2009, 09:14 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Search via SMF or Google: modx forums all of modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Can I Use eform to process form fields injected into the DOM with Javascript?  (Read 569 times)
0 Members and 1 Guest are viewing this topic.
therebechips
Sr. Member
****
Posts: 305


« on: Dec 22, 2008, 05:05 AM »

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:

Code:
<!--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
Logged
mrhaw
Committed to MODx
*****
Posts: 1,087


modx == freedom


WWW
« Reply #1 on: Dec 22, 2008, 05:23 AM »

I know nothing but I read this in the wiki:

Quote
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

« Last Edit: Dec 22, 2008, 05:38 AM by mrhaw » Logged

My playground: http://4up2date.info  | Host: (mt) Media Temple (gs) | Server: Apache 2.0 | MySQL 4.1.11 | PHP 5.2.6 | MODx 0.9.6.3 (patchwork)
therebechips
Sr. Member
****
Posts: 305


« Reply #2 on: Dec 22, 2008, 05:47 AM »

Quote

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...
Logged
mrhaw
Committed to MODx
*****
Posts: 1,087


modx == freedom


WWW
« Reply #3 on: Dec 22, 2008, 06:10 AM »

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
« Last Edit: Dec 22, 2008, 06:13 AM by mrhaw » Logged

My playground: http://4up2date.info  | Host: (mt) Media Temple (gs) | Server: Apache 2.0 | MySQL 4.1.11 | PHP 5.2.6 | MODx 0.9.6.3 (patchwork)
ZAP
Testers
*
Posts: 1,583



« Reply #4 on: Dec 22, 2008, 07:33 AM »

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.).
Logged

"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  | bug reports  | info you should include with your post | commercial support options
therebechips
Sr. Member
****
Posts: 305


« Reply #5 on: Dec 22, 2008, 09:44 AM »

@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.
Logged
ZAP
Testers
*
Posts: 1,583



« Reply #6 on: Dec 22, 2008, 08:18 PM »

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.
Logged

"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  | bug reports  | info you should include with your post | commercial support options
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF | SMF © 2006-2008, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!