Form Validation
Deprecated: Form Builder / Legacy Forms
Recommendation
Use a content type to create a form; use the workflow viewtool or workflow API to ingest each submission as a new contentlet of that content type.
See How to Build A Schema Driven Form in dotCMS for a tutorial.
Reason
Original legacy form functionalities, such as the FormTool, depended on Struts components, removed years ago — version 5.2.0, back in 2019.
The successor, the Form Builder, has likewise aged out; it renders out-of-date (sometimes nonstandard) tags that frequently fall short of WCAG or other standards, and custom fields like a captcha are not possible. Given more coherent alternative methods outlined above, we deemed this feature no longer worth updating.
There are multiple way to validate what is entered in each form. This document will cover the following:
Default Field Validation Messaging#
When creating forms as content, form field validation is automatically handled. If the fields are required on the form and not yet filled out, the user will not be able to submit until the form until it is filled. If a non-matching data type is submitted to a form field, an error message will automatically be generated to the user asking them to re-supply the invalid field information on the form. The error message will display the label of the form field as defined in the form structure.
Validation RegEx on Fields#
Validation RegEx makes sure the field it is applied to is following a specific pattern.
- First make a new text field. (In this example we will be using email)
- Next select the pattern you would like the field to follow from the RegEx drop down menu
- Save the field
Now when you view the form on your site and try to enter text that does not follow that pattern, you will not be able to submit your form until it does match the pattern.
##Custom Field Messaging on Forms {#CustomMessageForm}
The steps bellow apply to adding a custom field validation message to a field that is using a regex validation. The custom validation does not replace the error message seen if content of the wrong type is entered in a field.
- Edit the field(s) in the form
- Click on the "Field Variables" tab, and add a field variable with "errorFieldMessage" (case sensitive), as the Key of the field value. Write the custom message you would like to show in the Value field. If this field property is set, then the custom messaging typed in the Value field for the Field Variable will be displayed instead of the default validation messaging on the form.