Forums / Developer / Forms in eZ Publish

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

eZ debug

Timing: Jan 18 2025 03:04:54
Script start
Timing: Jan 18 2025 03:04:54
Module start 'content'
Timing: Jan 18 2025 03:04:54
Module end 'content'
Timing: Jan 18 2025 03:04:55
Script end

Main resources:

Total runtime0.8820 sec
Peak memory usage4,096.0000 KB
Database Queries205

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0071 587.6094180.8438
Module start 'content' 0.00710.7533 768.4531704.3594
Module end 'content' 0.76040.1216 1,472.8125346.3203
Script end 0.8820  1,819.1328 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.4318210.0002
Check MTime0.00150.1663210.0001
Mysql Total
Database connection0.00060.073710.0006
Mysqli_queries0.780188.44122050.0038
Looping result0.00210.23412030.0000
Template Total0.852896.720.4264
Template load0.00210.237720.0010
Template processing0.850796.447820.4254
Template load and register function0.00010.012610.0001
states
state_id_array0.00090.106410.0009
state_identifier_array0.00120.133020.0006
Override
Cache load0.00200.22351040.0000
Sytem overhead
Fetch class attribute can translate value0.00150.172250.0003
Fetch class attribute name0.00150.174990.0002
XML
Image XML parsing0.00280.322250.0006
class_abstraction
Instantiating content class attribute0.00000.0021100.0000
General
dbfile0.00350.3984460.0001
String conversion0.00000.000730.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
5content/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
16content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
3content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1content/datatype/view/ezxmltags/li.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/li.tplEdit templateOverride template
1content/datatype/view/ezxmltags/ul.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ul.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 65
 Number of unique templates used: 11

Time used to render debug report: 0.0002 secs