[TYPO3-mvc] validator: email, but not required?
Bastian Waidelich
bastian at typo3.org
Tue Feb 21 18:16:17 CET 2012
Stig Nørgaard Færch wrote:
> If I validate a property as e-mail, it will also fail an empty value. It
> of course makes some sense, as an empty value doesn't comply as an
> e-mail address.
This issue has recently been fixed in FLOW3 (after some discussion) [1].
Maybe someone feels like backporting this - unfortunately it is a
breaking change though..
> But I need it to pass when empty as well. What is the preferred to do
> this way?
Probably the easiest solution for now would be to create a
EmailOrEmptyValidator like:
class Tx_YourExt_Validation_EmailAddressOrEmptyValidator extends
Tx_Extbase_Validation_Validator_EmailAddressValidator {
public function isValid($value) {
if ($value === NULL || $value === '') {
return TRUE;
}
return parent::isValid($value);
}
}
(untested)
But, obviously this should be possible without custom validators too.
HTH
Bastian
[1] http://forge.typo3.org/issues/33300
More information about the TYPO3-project-typo3v4mvc
mailing list