Ask Your Question

How can a validator be created for field values in Typo3 when the record is saved in the database?

asked 2022-11-12 11:00:00 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-05-03 12:00:00 +0000

lakamha gravatar image

To create a validator for field values in Typo3, you need to follow these steps:

  1. Open the TypoScript setup.

  2. Use "TCA" (Table Configuration Array) to define the fields and their validation rules. For example:

    tca.<table>.columns.<fieldname>.config.validation = <validator>

    Here, <validator> is the validation rule that you want to apply to the field.

  3. Create a custom validation function that checks whether the field value is valid or not. You can do this using PHP code. For example:

    function myCustomValidator($value, $options) {
       if($value > $options['max']) {
           return 'Value too high';
       } elseif($value < $options['min']) {
           return 'Value too low';
       } else {
           return true;

    This function takes the field value as the first argument ($value) and an array of options as the second argument ($options). The function returns true if the value is valid, otherwise it returns an error message.

  4. Register your custom validation function using the extbase_validation hook. For example:

    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['validator']['<YourExtensionKey>']['<ValidatorName>'] = \Your\Extension\MyValidator::class;

    Here, <YourExtensionKey> is the key of your extension and <ValidatorName> is the name of your validator function.

  5. Save the record in the database. Typo3 will automatically call your custom validation function and show error messages if the field values are invalid.

Note: The above steps are just a general guideline. The actual implementation may vary depending on your specific requirements.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer

Question Tools


Asked: 2022-11-12 11:00:00 +0000

Seen: 21 times

Last updated: May 03 '21