Adding validations to fields in the Sitefinity Form builder

July 27, 2011 Digital Experience

The Forms module is one of the new great features we introduced in Sitefinity 4. You can use it to robustly build various user interaction forms, polls, questionnaires and more with the intuitive Sitefinity drag-and-drop interface.

Today we’ll explore the option to add validation to the text boxes, which are possibly the mostly used elements in every form. Let’s first create our form and add some widgets to it:

Now, if we would like to make sure that our visitors fill out the text boxes, there is a tick we can select in the text box’s designer window, which would make any of these fields are required:

So far, so good! However, what if we would like to make sure that the fields are filled out with content with a specific format? For example Text, Number or e-mail address? That’s absolutely possible and easy too! We need to go into the Advanced options of the textbox widget first:

and then proceed down to ValidatorDefinition:

Here we can fill out the field ExpectedFormat with the formatting the visitor is supposed to follow:

The different formatting options are listed in the offline Sitefinity documentation, that's available with the SDK. For ease of access, I've enclosed them below:

Value Purpose
None none by default
AlphaNumeric Validates alpha numerics
Currency Validates currency
EmailAddress Validates email addresses
Integer Validates integers
InternetUrl Validates internet urls
NonAlphaNumeric Validates non aplhanumerics
Numeric Validates numerics
Percentage Validates percentages
USSocialSecurityNumber Validates US social security numbers
USZipCode Validates US zip codes
Custom Validates against custom regular expression
GetRelatedItem Gets the item (live, temp or master) which is related with the specified item by lifecycle status. The method supports only items of type Content and ILifecycleDataItem
SetUIStatus Sets the UI status of a content object depending on whether this object also implements ILifecycleDataItemGeneric
GetUIStatus Gets the UI status of a content object depending on whether this object also implements ILifecycleDataItemGeneric
GetLanguageVersion Gets the language version.
GetUIStatusRaw
GetLanguageVersionRaw Gets the language version for the specified culture.
GetWrapperValue Gets the wrapper value.
GetPropertyValue Gets the property value.
CopyPropertiesFrom Copies all the properties of the "from" object to this object if they exist.
CopyPropertiesFrom Copies all the properties of the "from" object to this object if they exist.
CopyPropertiesTo Copies all the properties of this object to the "to" object
CopyPropertiesTo Copies all the properties of this object to the "to" object
GetSerializationPropertyValueCollection
GetListSerializationItemsItems



For example, if we would like our visitors to put an e-mail address in the text box we are configuring, we need to put EmailAddress in the ExpectedFormat field. We can also specify an error message if an invalid e-mail format is supplied:

And that’s that – validation is already in place! Let’s test the result:

The Progress Team