Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TYPO3/Extbase - How to trim values before validation/saving objects?

In Extbase usually I handle form validation myself within the controller, especially when I need advanced scenarios, but now I've simple, but large form with many fields, so I decided not to waste time and just use TYPO3's validators. So far so good in general it works, anyway I cannot force Extbase to trim values before validation and in result Extbase saves lot of spaces... so it's invalid, sample:

/**
 * @var string
 * @validate StringLength(minimum=2, maximum=255)
 * @validate NotEmpty
 */
protected $fooName = '';

As I said I've tens of fields and would love to avoid manual validating it... is there any solution?

Note: I tried extbase_filter ext, which would be great solution if it worked (unfortunately doesn't take any effect at TYPO3 ver.: 6.2.6.

Also for obvious reasons using JS for trimming values before form send isn't a solution too.

like image 740
biesior Avatar asked Dec 17 '25 20:12

biesior


1 Answers

You can do trim-ing inside your set* methods. Validation in Extabase's MVC process happens after set-ers invoked.

So, your example would be:

/**
 * @var string
 * @validate StringLength(minimum=2, maximum=255)
 * @validate NotEmpty
 */
protected $fooName = '';

public function setFooName($fooName)
{
    $this->fooName = trim($fooName);
}
like image 72
Viktor Livakivskyi Avatar answered Dec 20 '25 14:12

Viktor Livakivskyi