Aswathy S
Aswathy S

Reputation: 729

Typo3 validator returns Call to a member function addError() on null

I have a fluid form.On completion of edit an ajax call is passed to controller i make an instance of EmailAddressValidator() My code is given below

$validate =  \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Validation\\Validator\\EmailAddressValidator');
$result = $validate->isValid('[email protected]');

It returns nothing if the email is in correct format.But it returns

Call to a member function addError()

if the format is incorrect.

Upvotes: 0

Views: 591

Answers (1)

Jost
Jost

Reputation: 5840

(Updated)

The problem is how you call the validator. You need to call the method validate, not isValid.

So this should work:

$validate =  \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Validation\\Validator\\EmailAddressValidator');
$result = $validate->validate('[email protected]');

$result is an instance of TYPO3\CMS\Extbase\Error\Result, you can use the method hasErrors on it to check if the mail was valid.

Upvotes: 2

Related Questions