Forums / Developer / Unable to retrieve fields names with $http->postVariable

Unable to retrieve fields names with $http->postVariable

Author Message

Andrea Sudetti

Thursday 17 September 2009 4:31:24 am

Hi all,
I'm a newbie and I have a question regarding the custom input validation as extension of eZContentObjectEditHandler class.

I've read this article http://serwatka.net/blog/enhanced_content_edit_handler_for_validation_rules_in_ez_publish_4_1 and I've made my own custom handler to validate input fields.
Now... the question... In that article, the name of the variable retrieved is an "easy name" ('ExampleTextField') but when I'm trying to retrieve fields from my form, the name that ezpublish assigns them is something like "ContentObjectAttribute_type_id".

Obviously these names change in every form accordingly to the field type and the element id and my custom handler "can't handle" nothing if I am not able to retrieve them with the "easy name" I've assigned them in the class that i've created.

I've tried to realize a custom edit template changing the field names but I've another problem (obviously): the standard validation don't work anymore...

Where am I wrong?
Thank you in advance.

A.

Łukasz Serwatka

Thursday 17 September 2009 6:12:45 am

Hi,

You can use basic string joining like

Quick example (I did not test it, watch out on typos)
class MyCustomValidatorHandler extends eZContentObjectEditHandler
{
    const base = 'ContentObjectAttribute';

    function fetchInput([...] $contentObjectAttributes [...] )
    {
        $http = eZHTTPTool::instance();

        foreach( $contentObjectAttributes as $contentObjectAttribute )
        {
            $inputName = self::base . '_' . $contentObjectAttribute->attribute('data_type_string') . '_' . $contentObjectAttributes->attribute( 'id' );

        // Here you can filter also on identifier by getting value form $contentObjectAttribute

        if ( $http->hasPostVariable( $inputName ) )
        {
            $formInput = $http->postVariable( $inputName );
        }
    }
}

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Andrea Sudetti

Friday 18 September 2009 3:49:13 am

Thank you man, but I still have a problem...

The attribute ('data_type_string') return me type like"eztext" but, the data type of the field name (in the submitted form) is "data_text"... and so on for other data types...

There's another attribute I've to specify instead of 'data_type_string'?

Thanks again
A.

Łukasz Serwatka

Friday 18 September 2009 4:19:11 am

Could you explain in details what are you trying to do? Why do you need validation for existing datatypes? They already has some validation where this is needed. Do you need something extra?

I have feeling that content edit handler and validation is miss used a bit here. Hope I'm wrong ;)

You can do mapping between submitted contentobject attribute identifiers and their appropriate input form names. The identifier you can get from the $contentObjectAttribute

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

André R.

Friday 18 September 2009 4:20:01 am

> There's another attribute I've to specify instead of 'data_type_string'?
Actually, this is defined in the templates of the datatypes, and is unfortunately not following any rules so could be anything.

If you only need for that attribute use something like:

$inputName = self::base . '_data_text_' . $contentObjectAttributes->attribute( 'id' );

For all datatypes you can simply check their validateObjectAttributeHTTPInput() or fetchObjectAttributeHTTPInput() methods to see what kind of post parameter pattern they use.
eztext: kernel/classes/datatypes/eztext/eztexttype.php

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Andrea Sudetti

Friday 18 September 2009 5:29:42 am

Ok, let's try to explain...

Users can create contents with webtoolbar.

Every content contains some "free fields" and others fields (two images and a movie) that can be filled ONLY if the users have enough "credits".

I'll check credits client-side but I wanna be sure that the "main" control will be made after submission server-side (to avoid hacks and tricks ;) ) , so I wanted to check with validateInput: check submission of three extra fields, if they are submitted, check credits and then validate or not.

The problem is to retrieve specifics fields names to validate...

Sorry for my poor english (and my poor ez-knowledge... ;) )

Thank you guys!

Andrea Sudetti

Friday 25 September 2009 9:24:28 am

Hi guys,
first of all I wanna thank you for your guidelines, I solved almost all my problems...

I have another question... I have to validate an object (in a custom edit handler), but in validateinput function I'm not able to retrieve the parent node id until I don't publish it.

I check conditions in publish function, I can remove the node but I'm not able to alert the user after redirect.

    function publish( $contentObjectID, $contentObjectVersion ){
        $object =& eZContentObject::fetch( $contentObjectID );
        $contentClass =& $object->attribute('content_class');
		if($contentClass->attribute('id') == 51){
			include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
			$nodooffertaID = $object->attribute('main_node_id');
			$offerta = eZContentObject::fetchByNodeID($nodooffertaID);
			$parentNodeID = $object->attribute('main_node_id');
			$oggettoofferta = eZContentObjectTreeNode::fetch($parentNodeID);			
			$nodoastaID = $oggettoofferta->attribute('parent_node_id');
			$oggettoasta = eZContentObject::fetchByNodeID($nodoastaID);
			$dataMapasta = $oggettoasta->dataMap();
			$chiusuraasta = $dataMapasta['data_chiusura'];
			$datachiusura = $chiusuraasta->attribute('data_int');
			if($datachiusura < mktime()){
                                //remove object
				eZContentObjectTreeNode::removeNode($nodooffertaID);
			}
		}
	}

I think if I can validate the object in validateinput I can alert user and then redirect him on the edit page with the alert message...

Thankyou in advance

eZ debug

Timing: Jan 18 2025 11:12:57
Script start
Timing: Jan 18 2025 11:12:57
Module start 'content'
Timing: Jan 18 2025 11:12:58
Module end 'content'
Timing: Jan 18 2025 11:12:58
Script end

Main resources:

Total runtime1.1380 sec
Peak memory usage4,096.0000 KB
Database Queries208

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0059 589.0703180.8125
Module start 'content' 0.00590.9592 769.8828651.8672
Module end 'content' 0.96510.1728 1,421.7500345.0391
Script end 1.1379  1,766.7891 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00430.3818210.0002
Check MTime0.00150.1348210.0001
Mysql Total
Database connection0.00060.052010.0006
Mysqli_queries1.050692.31622080.0051
Looping result0.00220.19532060.0000
Template Total1.108097.420.5540
Template load0.00220.189420.0011
Template processing1.105897.169320.5529
Template load and register function0.00020.014210.0002
states
state_id_array0.00150.128810.0015
state_identifier_array0.00150.135420.0008
Override
Cache load0.00190.1692520.0000
Sytem overhead
Fetch class attribute can translate value0.00160.142640.0004
Fetch class attribute name0.00100.087490.0001
XML
Image XML parsing0.00160.140540.0004
class_abstraction
Instantiating content class attribute0.00000.0016100.0000
General
dbfile0.00570.5034360.0002
String conversion0.00000.000430.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
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
12content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/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: 34
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs