[TYPO3-mvc] Own Object Validator

Gianluca Strafella gianluca.strafella at webformat.com
Mon Nov 11 09:17:58 CET 2013


Hi Stefn,
in your validator method "isValid", you should add an error with:

$this->addError('Email not unique', 84647862842);

if you need to translate error message you can use extbase 
"LocalizationUtility" class, in example:

 
$this->addError(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate( 
                                'validator.email.notunique', 
                     'your_extention_key'), 1221559976);

You can view errors in frontend with a Partial, named as 
"FormErrors.html" localized in YouExtention/Resources/Private/Partials/ 
directory.

In this partial you can iterate on form errors with fluid tags 
"f:form.errors" or  "f:form.validationResults".

Useful links are:

http://docs.typo3.org/typo3cms/ExtbaseFluidBook/9-CrosscuttingConcerns/2-validating-domain-objects.html
http://forge.typo3.org/projects/typo3v4-mvc/wiki/Translated_validation_error_messages_for_Fluid
http://wiki.typo3.org/Fluid#f:form.errors

Regards,
Gianluca

Gianluca Strafella

Software Developer
gianluca.strafella at webformat.com
Tel.   +39-0427-926.389

WEBFORMAT srl – www.webformat.com
Via Mecenate, 76 - 20138 MILANO
Corte Europa, 12 - 33097 SPILIMBERGO (PN)


Il 07/11/2013 19:38, Stefan Kruse ha scritto:
> Hi,
>
> i have a form use my own validator. Inside the isValid method I make my
> validation and add if need the error with $this->addError(...);.
> Could someone explain how to make a property error? I found this, but that
> doesn't work. Is there a other way?
>
>
> /**
> * @param Tx_ExtensionName_Domain_Model_ModelName $value
> * @return bool
> */
> public function isValid($value)
> {
> $this->errors = array();
>
> if ($this->modelNameRepository->findByEmail($value->getEmail())->count() >
> 0) {
>      $this->errors['email'] = new
> Tx_Extbase_Validation_PropertyError('email', time());
>      $this->errors['email']->addErrors(array(new
> Tx_Extbase_Validation_Error('Email not unique', 84647862842)));
>
>      return false;
> }
>
>      return true;
> }
>
> Thanks STefn
>


More information about the TYPO3-project-typo3v4mvc mailing list