eZ Community » Forums » Developer » Dynamic form creation, validation and...
expandshrink

Dynamic form creation, validation and storing of data

Dynamic form creation, validation and storing of data

Friday 07 January 2011 10:59:13 am - 5 replies

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

Saturday 08 January 2011 12:56:26 am

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

Tuesday 11 January 2011 10: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.

Tuesday 11 January 2011 11: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!

Tuesday 11 January 2011 12:43:57 pm

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.

Tuesday 11 January 2011 2:21:57 pm

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.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from