Forms in eZ Publish

Author Message

Piotrek Karaś

Monday 26 October 2009 4:54:44 am

Hello all,

What are your common needs regarding creating and managing forms in eZ Publish, and how do you deal with them? Are there any projects available that make that easier?

I'm trying to reapproach the topic and want to make sure I haven't missed anything worth checking out. Any thoughts greatly appreciated!

Cheers,
Piotrek

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Alex Kozeka

Wednesday 27 January 2010 1:23:52 am

Hi Piotrek,

These are my questions and thoughts about what should possible to do in eZ Publish:

- Is it possible to create/handle HTML form without using eZ content objects and their datatypes?
- How to create custom/extra validation rules for the form? For example:
Need to:
* validate that input1 is greater than input2 (integer or date)
* validate that sum of input1 and input2 is not greater than specific number
Strict requirement is that inputs don't loose their values after form was sent and was displayed again.
- How to create different sets of validation conditions for different view-contexts of the form?
Example: When adding object - validate all fields. When editing - just some of them. If adding/editing by admin - validate just one field.
- What are 'hooks' in terms of eZ Publish? Where can find an example of their usage? And how can they be used for adding custom actions for existing PHP modules?
For example in "kernel/user/register.php" you can find this line:
$Module->addHook( 'post_publish', 'registerSearchObject', 1, false );
- How to create view-context specific form input labels for the form?
Example: Let's say for site administrator some form field labels are "Customer1 Name", "Customer2 Name" and for anonymous users those labels should be "Director", "Manager".
- How to create different forms for "Adding" and "Editing" content object and possibly with slightly different fields labels?
- How to post-process values of fields of sent form before adding/updating actual data to DB with custom PHP code?
Example: Need to do 'normalization' of names before saving, like: user input was "john sMITH" and it should be "John Smith".

PS: WYSIWYG editor didn't work under IE!

Cheers,

Alex

--
Argentea S.p.A., http://www.argentea.it/

Bruce Morrison

Wednesday 27 January 2010 5:52:25 pm

Hi Alex

I'll attempt to answer your questions - there is a lot to cover here :)

 - Is it possible to create/handle HTML form without using eZ content objects and their datatypes?

Yes there  are a number of solutions in the form of extensions. Check out eZ Survey (GPL, certified and part of eZ publish 4.2) or Form Builder from designIT (Commercial - I wrote this when I worked for them).

Also check out Paul Wilson's article http://ez.no/de/developer/articles/how_to_create_ez_publish_forms

How to create custom/extra validation rules for the form? For example:
Need to:
* validate that input1 is greater than input2 (integer or date)
* validate that sum of input1 and input2 is not greater than specific number
Strict requirement is that inputs don't loose their values after form was sent and was displayed again.

You might be able to do something with eZContentObjectEditHandler Validation - See http://serwatka.net/blog/enhanced_content_edit_handler_for_validation_rules_in_ez_publish_4_1

The other option is to create a custom datatype to handle this situation. This is the option I'd choose.

- How to create different sets of validation conditions for different view-contexts of the form?
Example: When adding object - validate all fields. When editing - just some of them. If adding/editing by admin - validate just one field.

This is where you'd use  eZContentObjectEditHandler Validation however I believe you cannot override the existing validation present in the base datatype.  I think this is executed after.

 - What are 'hooks' in terms of eZ Publish? Where can find an example of their usage? And how can they be used for adding custom actions for existing PHP modules?
For example in "kernel/user/register.php" you can find this line:
$Module->addHook( 'post_publish', 'registerSearchObject', 1, false );

Hooks are mainly used to attach workflow but can be used in modules.  There is not a lot of good documentation on this part of eZ. The following may be of some value

  • http://pubsvn.ez.no/doxygen/trunk/html/classeZModule.html
  • http://ez.no/doc/ez_publish/technical_manual/4_x/concepts_and_basics/workflows

 - How to create view-context specific form input labels for the form?
Example: Let's say for site administrator some form field labels are "Customer1 Name", "Customer2 Name" and for anonymous users those labels should be "Director", "Manager".

The simplest way to do this is create an edit template override that is displays the required label dependant on the user/group viewing it.

-  How to create different forms for "Adding" and "Editing" content object and possibly with slightly different fields labels?

As above but checking on the version number to determine if the object is new or not.

-  How to post-process values of fields of sent form before adding/updating actual data to DB with custom PHP code?
Example: Need to do 'normalization' of names before saving, like: user input was "john sMITH" and it should be "John Smith".

Create a custom pre-publish workflow.  Have a look at the items under  http://pubsvn.ez.no/nextgen/trunk/kernel/classes/workflowtypes/event/ specifically http://pubsvn.ez.no/nextgen/trunk/kernel/classes/workflowtypes/event/ezwaituntildate/ezwaituntildatetype.php and http://pubsvn.ez.no/nextgen/trunk/kernel/classes/workflowtypes/event/ezapprove/ezapprovetype.php

Hope this goes some way to answering your questions.

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

Alex Kozeka

Wednesday 27 January 2010 11:56:50 pm

Thank you for replies Bruce!

Now I have the path to investigate.

BTW: Good blog!

--
Argentea S.p.A., http://www.argentea.it/

Veronique Jamilloux

Tuesday 01 June 2010 7:02:15 am

Hi,

I've the same questions the Alex about the validation fields of my form.

I read the exellent "How to Create eZ Publish Forms" documentation from Paul Wilson. I read also "Enhanced content edit handler for validation rules in eZ Publish 4.1" from Lukasz but I don't really understand very well all the indications.

In my form there are 2 fields email and email_confirm and I would like verify if they are equal. In which file I can put the validation rule in template/content/collectedinfo_validation.tpl?

In my old website I used a java script fonction in the form page :

function validate_equals(field1, field2, alerttxt) {
 with (field1) {
   if (value!=field2.value) {
    alert(alerttxt);
    return false;
   }
   else {
    return true;
   }
 }
}

Is there anybody to tell me how can make this validation rule?

I use eZpub 4.2.0

Thank a lot for your answers.

Véronique

URGI - INRA
Webmaster
Route de Saint Cyr
78000 Versailles

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.