Forums / Developer / Unable to retrieve fields names with $http->postVariable
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 Exponential 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
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 againA.
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
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
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!
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