You are browsing upcoming documentation for version 6.0 of OroCommerce, OroCRM, and OroPlatform, scheduled for release in 2024. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.

See our Release Process documentation for more information on the currently supported and upcoming releases.

Forms and Validators Configuration

The Symfony Validation Component and Forms Component are used to validate and transform input data to an entity in create, update, update_relationship, add_relationship and delete_relationship actions.


The validation rules are loaded from Resources/config/validation.yml and annotations, as is commonly done in Symfony applications. So, all validation rules defined for an entity also apply to the API. API uses two validation groups: Default and api. If you need to add validation constraints that should be applied in the API only, add them to the api validation group.

Suppose a validation rule cannot be implemented as a regular validation constraint due to its complexity. In that case, you can implement it as a processor for the post_validate event of the customize_form_data action. Keep in mind that FormUtil class contains methods that may be useful in such a processor.

If the input data violate validation constraints, they will be automatically converted into the validation errors that help build the correct response of the API. The conversion is performed by the CollectFormErrors processor. By default, the HTTP status code for validation errors is 400 Bad Request. To change it, you can:

The following example shows how to add validation constraints to the API resources using the Resources/config/oro/api.yml configuration file:

                            # add Symfony\Component\Validator\Constraints\Email validation constraint
                            - Email: ~
                            # add Symfony\Component\Validator\Constraints\Length validation constraint
                            - Length:
                                max: 50
                            # add Acme\Bundle\DemoBundle\Validator\Constraints\Alphanumeric validation constraint
                            - Acme\Bundle\DemoBundle\Validator\Constraints\Alphanumeric: ~

Also, see how to validate virtual fields.

In case you need to replace an error title returned by the API with another error title, use the error_title_overrides configuration section in Resources/config/oro/app.yml in any bundle or config/config.yml of your application, e.g.:

        'percent range constraint': 'range constraint'


The API forms are isolated from the UI forms. This helps avoid collisions and prevent unnecessary performance overhead in the API. Consequently, all the API form types, extensions, and guessers should be registered separately. There are two ways to complete this:

  • Use the application configuration file.
  • Tag the form elements with appropriate tags in the dependency injection container.

To register new form elements using the application configuration file, add Resources/config/oro/app.yml in any bundle or use config/config.yml of your application.

        - Symfony\Component\Form\Extension\Core\Type\DateType # the class name of a form type
        - # the service id of a form type
        - form.type_extension.form.http_foundation # service id of a form type extension
        - acme.form.type_guesser # service id of a form type guesser
        datetime: # data type
            form_type: Symfony\Component\Form\Extension\Core\Type\DateTimeType # the guessed form type
            options: # guessed form type options
                model_timezone: UTC
                view_timezone: UTC
                with_seconds: true
                widget: single_text
                format: "yyyy-MM-dd'T'HH:mm:ssZZZZZ" # HTML5


The form_types section can contain either the class name or the service id of a form type. Usually, the service id is used if a form type depends on other services in the dependency injection container.

You can find the already registered API form elements in Resources/config/oro/app.yml.

If you need to add new form elements can by tagging them in the dependency injection container, use tags from the following table:

Tag Description
oro.api.form.type Create a new form type
oro.api.form.type_extension Create a new form extension
oro.api.form.type_guesser Add your own logic for “form type guessing”


    class: Acme\Bundle\DemoBundle\Form\Type\DateTimeType
        - { name: form.type, alias: acme_datetime } # allow to use the form type on UI
        - { name: oro.api.form.type, alias: acme_datetime } # allow to use the form type in API

    class: Acme\Bundle\DemoBundle\Form\Extension\DateTimeExtension
        - { name: form.type_extension, alias: acme_datetime } # add the form extension to UI forms
        - { name: oro.api.form.type_extension, alias: acme_datetime } # add the form extension to API forms

    class: Acme\Bundle\DemoBundle\Form\Guesser\TestGuesser
        - { name: form.type_guesser } # add the form type guesser to UI forms
        - { name: oro.api.form.type_guesser } # add the form type guesser to API forms

To switch between the general and API forms, use the Processor\Shared\InitializeApiFormExtension and Processor\Shared\RestoreDefaultFormExtension processors.

The Processor\Shared\BuildFormBuilder processor builds the form for a particular entity on the fly based on the API configuration and the entity metadata.