Forums / Developer / Form validation

Form validation

Author Message

Jérôme Vieilledent

Monday 03 September 2007 7:49:28 am

Hello,

I would like to know how I can do form validation in EZ Publish (I work with 3.9.2). Indeed, this part is not well documented unfortunately :-(.
I saw that there are several ways to collect information. One of them is to set class attributes for information collection. But in my case it is not possible as the form has to be built dynamically. I would like to create an action (content/action) extension, but how do I validate the form ? If a user misses a field, I have to re-display the form and to repopulate it, with a custom error message indicating that the user omitted to fill one or several fields.

Can you please help me ?

Lazaro Ferreira

Monday 03 September 2007 9:07:48 am

Hi,

May you explain your problem further

what does mean <b>the form has to be built dynamically</b> ?

Regards

Lazaro
http://www.mzbusiness.com

Jérôme Vieilledent

Monday 03 September 2007 1:27:17 pm

Hi Lazaro and thanks for your reply :-)

OK, i'm gonna try to explain further...
My site is for a travel agency and proposes several destinations. Each destination has a commercial proposition, but the user must have the opportunity to build his own. For that, each destination has predefined fields which are defined in the admin. The administrator must have the possibility to add as many fields (or options) as he wishes.
Thus, this form has to be built dynamically, with these parameters...

I made a class named <b>"Destinations"</b> with an attribute (actually 2) for the options. The datatype I chose for this attribute is <b>"Option"</b>, so that the admin would be able to add as many as he wishes. I don't know if this is the best way for that, but it seemed quite efficient to me.
You can see an example (not made with EZ Publish) here : http://horizon-pleine-nature.com/destinations/composer/2.html

Another question related with this site. I would like to do a contact form and for that I made a class "Contact", with attributes marked as "information collector". In my template I made a HTML form with <b>/action/content</b> action and a POST method. I named the submit button <b>ActionCollectInformation</b>, but when I post the form, EZ Publish tells me that <i>the object is not available</i>... I tried many things but nothink seemed to work :-(

Thanks for your help

Bruce Morrison

Monday 03 September 2007 4:58:29 pm

Hi Jérôme

Our form bulider product may be of interest to you
http://ez.no/products/partner_products/form_builder

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Jérôme Vieilledent

Tuesday 04 September 2007 6:59:39 am

Thanks Bruce :-), but I need an open source solution since I'm learning EZ Publish... I have to understand how it works.

Olivier Ouin

Tuesday 04 September 2007 11:23:05 am

About your "validation" question, I think using the "option" datatype as information collector would be a good choice if you didn't have the text to set when selecting "other".

In EZP, validation implementation is bring by datatypes themselves.
See these methods :
validateClassAttributeHTTPInput (validate input from a class edit form)
validateObjectAttributeHTTPInput (validate input from a content object edit form)
validateCollectionAttributeHTTPInput (validate input from an information collector form)
You can find them explained by comments in eZDataType class, in the /kernel/classes/ezdatatype.php.
Each datatype extends this class, and need to overload these methods to implement their specific validation.

If you can't found existing datatypes that meet your needs, I suggest you to build your own, and made it to work as an information collector.

You can also imagine not use information collection but rather create custom objects in your content tree, but it won't spare you the task to write custom datatypes if it's really needed.. you will have to validate the object rather than the information collection : the complexity is only moved, and more, it may make your content tree becoming really huge, and the collected data would be more difficult to use (especially if usage is externalised).

The last otion I see would be to create a custom eZ module, in which you will be free about data storing, retrieving, validating and so. You can build your script nearly as you would have done with a standard php site, and associate it with a template.

For your second question about the "object is not available error", do you have passed the object IDs into hidden fields into your form ?
You should at least have something like this in your template:
<input type="hidden" value="{$object.id}" name="ContentObjectID"/>

Jérôme Vieilledent

Saturday 15 September 2007 6:02:57 am

Thanks for your reply Olivier.

Thanks to you I managed to make my contact form to work :-).
For the other validation stuff, I've decided to make a custom form action bundled in an extension (it seems to be quite easy). The problem is that this part of EZ Publish is very poorly documented... How can I validate my form properly (and so associate a template to show the errors and re-popuplate the form), and how can I just display a confirmation message ?

I read in the book that it is also possible to make a module for that, and to post the form to a module view, but it seems to be much more complicated...
The only thing I want to do is to simply validate my form...

Thanks for your help :-)

Matteo Giordani

Thursday 04 October 2007 3:14:24 am

Hello!
I have the same problem with the form validation issue.
I've developed a custom form...something like that:

http://ez.no/ezpublish/documentation/customization/components/information_collection

Everything work fine, the validation seems work... but i'm not able to retrive any validation error message.

that kind of include doesn't work...

{include name=Validation uri='design:mystandardoverride/mycollectedinfo_validation.tpl'
class='message-warning'
validation=$validation collection_attributes=$collection_attributes}

i don't know why!!!
Thanks for your help.

 

eZ debug

Timing: Jan 18 2025 11:29:03
Script start
Timing: Jan 18 2025 11:29:03
Module start 'content'
Timing: Jan 18 2025 11:29:04
Module end 'content'
Timing: Jan 18 2025 11:29:04
Script end

Main resources:

Total runtime1.2142 sec
Peak memory usage4,096.0000 KB
Database Queries215

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0062 588.7188180.8516
Module start 'content' 0.00621.0717 769.5703731.1484
Module end 'content' 1.07790.1363 1,500.7188344.4531
Script end 1.2142  1,845.1719 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00480.3981210.0002
Check MTime0.00220.1825210.0001
Mysql Total
Database connection0.00060.051510.0006
Mysqli_queries1.118792.13152150.0052
Looping result0.00260.21442130.0000
Template Total1.187297.820.5936
Template load0.00220.182320.0011
Template processing1.185097.591620.5925
Template load and register function0.00010.008610.0001
states
state_id_array0.00160.133610.0016
state_identifier_array0.00070.060520.0004
Override
Cache load0.00200.1606700.0000
Sytem overhead
Fetch class attribute can translate value0.00110.093260.0002
Fetch class attribute name0.00170.1392100.0002
XML
Image XML parsing0.00160.134360.0003
class_abstraction
Instantiating content class attribute0.00000.0027130.0000
General
dbfile0.00230.1887340.0001
String conversion0.00000.000630.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
8content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
19content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
12content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 46
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs