Forums / Developer / Dynamic form creation, validation and storing of data

Dynamic form creation, validation and storing of data

Author Message

Matthew Dawkins

Friday 07 January 2011 1:59:13 am

First, the obligatory statement of newbieness... Hi everyone!

Now, I've been doing a fair amount of digging around in these forums and in eZ Publish itself, and haven't found the answers I've been looking for, so I'd like to ask you folks directly. I have a situation where I would like to have forms created dynamically by Javascript, using jQuery to duplicate certain inputs and other objects so that the user can enter an arbitrary number of inputs. That inputted data would obviously need to be validated, ideally both at client and server sides for additional security, and include a CAPTCHA verification as well. And then all that data would need to be stored somewhere so that I can access it from another system on another server.

An example would be where we might collect information about a person's pets, and we'd want them to be able to enter details for as many or as few as they like.

From what I can see, a dynamic form like this is not going to sit well with the built-in class and data collector approach used in eZ Publish. So, is it possible to create a form manually, rather than using the eZ P stuff, but still have the form appear on an EZP page? I'm guessing I would also have to take responsibility for parsing that input and storing it appropriately, effectively bypassing the whole EZP system completely, which seems a shame given the apparent power of it.

If you know of way of achieving all this in EZP, please do let me know, I'm all ears! Otherwise, if I have to do it manually, can anyone suggest how I might show this custom code on a page?

MD

Edi Modrić

Friday 07 January 2011 3:56:26 pm

Hi Matthew,

you could create a custom datatype that suits your needs (supports collection) and in the process, write custom validation code.

That way, validation process would nicely plug in to eZ Publish publishing and collecting process.

The following article can get you started on creating your datatype:

http://share.ez.no/learn/ez-publish/creating-datatypes-in-ez-publish-4

eZ Publish certified developer

http://ez.no/certification/verify/350658

Bertrand Dunogier

Tuesday 11 January 2011 1:24:25 am

Hi, and welcome !

The closest thing I can think of is the ezsurvey extension: http://projects.ez.no/ezsurvey. It is quite old (there might be newer versions out there), but it shows an approach to dynamic form. It doesn't use jQuery or anything really fancy, but it might give you ideas.

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Matthew Dawkins

Tuesday 11 January 2011 2:30:36 am

@Edi Thanks for that link re custom datatypes. Looks like quite an involved process for something so simple, and even then I'm not sure it actually fits the bill because I need an arbitrary number of inputs rather than EZP knowing beforehand what's coming.

@Bertrand Yes I had a look at ezsurvey before, but not as a source of inspiration for making my own extension, which looks like my best option at the moment. I'll have a look at the source code for that and see if I can glean any info about dynamic forms which I can use.

At the moment my general feeling is that despite EZP's obvious power and flexibility, it's far from being a rapid development platform - it's so complex that even doing something simple seems to take forever. I'm trying my best not to be put off, but it seems like an uphill climb at the moment!

Patrick Kaiser

Tuesday 11 January 2011 3:43:57 am

A custom datatype can store anything what you want. You can either use a dedicated table for it or store the value as a serialized php array. And yes, you maybe right, that there is no really simple way of doing this "the ez way", especially if you are not yet familiar with ez internals. Have a look at the build in matrix datatype, since it already does most what you need.


Best regards,

Patrick

Gaetano Giunta

Tuesday 11 January 2011 5:21:57 am

You can create a custom datatype that allows a variable number of values to be stored into it. It will be quite a bit of work, but I think it would be very, very much welcome by the community if done properly.

You could look at the code that does the 'variable number of items' part for those datatypes that allow that at the class level (eg. the options datatypes) and morph it into something that does the same but at the object level.

But that could prove also to be insufficient if what you want to do is to have a list with a variable number of values where each value is in fact not a scalar value but a complex object in itself (eg. pet's name, type, age, etc). In that case you might want to create one content object per pet, as child of the current node (or one information-collection per pet). Usage of the powercontent extension and some serious ajax/javascript-fu most likely needed.

Principal Consultant International Business
Member of the Community Project Board