
One of the new features in the upcoming eZ Publish 4.1 release is an enhanced content edit handler, which enables you to implement custom validation rules. Based on Kristof Coomans' "Object validation" extension, eZ Publish 4.1 will include the possibility to insert custom validation methods in the content object storing process.
There are many potential uses for this enhanced handler, including cross-attribute validation; enforcement of storage quotas when uploading files or creating content; CAPTCHA checks without needing to create datatypes; and much more.
Let's see how it works in practice. We use the custom edit handler with one additional method responsible for validation - “validateInput”. You can learn more about the custom edit handler here.
In its simplest form, it looks like this:
class MyCustomValidatorHandler extends eZContentObjectEditHandler { function __construct() { } function fetchInput( $http, &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage ) { } static function storeActionList() { } function publish( $contentObjectID, $contentObjectVersion ) { } function validateInput( $http, &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage, $validationParameters ) { $result = array( 'is_valid' => true, 'warnings' => array() ); return $result; } }
The handler must be placed in: extension/<extension-name>/content/<extension-name>handler.php. As always, the custom edit handler must be registered in a content.ini.append.php file as follows:
[EditSettings] ExtensionDirectories[]= mycustomvalidator
Now a few notes about the validateInput method. The result is an array where one item is an is_valid boolean value, informing the system about the validation status; the second item is a warnings array where you can put relevant information about what went wrong.
Example:
function validateInput( $http, &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage, $validationParameters )
{
$result = array( 'is_valid' => true, 'warnings' => array() );
$isValid =& $result['is_valid'];
$warnings =& $result['warnings'];
$phrase = $http->postVariable( 'ExampleTextField' );
if( $phrase == '' )
{
$warnings[] = array( 'text' => ezi18n( 'extension/mycustomvalidator', 'The verification word is not valid' ) );
$isValid = false;
}
return $result;
}
When the validation fails (in this simple case, the user has left a required text field empty), the "The verification word is not valid" text is displayed to user.

postVariables names??
Wednesday 16 September 2009 6:36:08 pm
ranx ‹ranx74_at_yahoo.com›
What about postVariables names?!
When I try to get http->postVariable i had to specify the "complex" name ("ContentObjectAttribute_ezstring_data_text_1928" for example) and I don't get any result if i specify the "real" name of the attribute ("titolo" for example)... Where am I wrong?
Thanks