Validating and hiding fields

Using the below shown TypoScript configuration allows to change the validation and rendering of fields of the billing and shipping address. The partials for the display of the addresses evaluates this configuration. It controls whether the fields are mandatory, optional or not rendered at all.

EXT:cart/Configuration/TypoScript/setup.typoscript
plugin.tx_cart {
    settings {
        validation {
            billingAddress {
                fields {
                    salutation.validator = NotEmpty
                    title.validator = Empty
                    firstName.validator = NotEmpty
                    lastName.validator = NotEmpty
                    email.validator = NotEmpty
                    phone.validator = Empty
                    fax.validator = Empty
                    company.validator = Empty
                    taxIdentificationNumber.validator = Empty
                    street.validator = NotEmpty
                    streetNumber.validator = Empty
                    addition.validator = Empty
                    zip.validator = NotEmpty
                    city.validator = NotEmpty
                    country.validator = NotEmpty
                }
            }
            shippingAddress {
                fields {
                    salutation.validator = NotEmpty
                    title.validator = Empty
                    firstName.validator = NotEmpty
                    lastName.validator = NotEmpty
                    email.validator = NotEmpty
                    phone.validator = Empty
                    fax.validator = Empty
                    company.validator = Empty
                    taxIdentificationNumber.validator = Empty
                    street.validator = NotEmpty
                    streetNumber.validator = Empty
                    addition.validator = Empty
                    zip.validator = NotEmpty
                    city.validator = NotEmpty
                    country.validator = NotEmpty
                }
            }
        }
    }
}
Copied!

Available validation options

The following examples show the available configuration options. The examples use the field salutation of the invoice address.

Option Not Empty

NotEmpty means the field is mandatory. This has the following consequences:

  • The field is rendered.
  • The label of the field is rendered with a trailing "*".
  • The input field is rendered with the attribute required set to true.
EXT:sitepackage/Configuration/TypoScript/constants.typoscript
plugin.tx_cart.settings.validation.billingAddress.fields {
    salutation.validator = NotEmpty
}
Copied!

Option Empty

Empty means that the field MUST be empty. This has the following consequences:

  • The field is not rendered at all.
  • The server checks whether the field is empty.
EXT:sitepackage/Configuration/TypoScript/constants.typoscript
plugin.tx_cart.settings.validation.billingAddress.fields {
    salutation.validator = Empty
}
Copied!

No validation

This has the following consequences:

  • The field is rendered.
  • The label of the field is rendered without a trailing "*".
  • The input field is rendered without the attribute required.
EXT:sitepackage/Configuration/TypoScript/setup.typoscript
plugin.tx_cart.settings.validation.billingAddress.fields {
    # !!! It is necessary to remove the whole address field,
    #     not only the `validator` configuration.
    salutation >
}
Copied!