OpenWGA 7.6 - OpenWGA Concepts and Features

Design and development » WebTML » Features » Forms

Validation

WebTML forms offer functionality to define validation expressions for input fields or the whole form, that are automatically validated when the form contents should get stored.

A validation for an individual input field  is defined using attribute validation. It should contain a TMLScript expression that is evaluated to validate if the input field contains valid data. The expression should return true if the field data is valid and false if it is not.

In a validation script the TMLForm may be used to retrieve form data to test, but most times it is more practical to use the predefined WebTML-Variables $E_VALUE and $P_VALUE in it. Both values represent the value of the field that owns the validation. But while $E_VALUE contains the unprocessed, entered text value of the field $P_VALUE contains the value that was parsed and converted to the target data type. For example the $E_VALUE for an input field of type "number" may be a string like "1.2345". $P_VALUE for this field will contain the actual number value of 12345 that will get stored to the data backend.

Accompanying the "validation" attribute is the message attribute which defines a message to put out when the validation fails:

<tml:input name="surname" type="text" validation="!isEmptyValue($E_VALUE)" message="The surname may not be empty!"/>

You may define multiple validations and their messages on one input by specifying attribute validationdivider and using whatever character you specified there as divider for your validation expressions and messages. The first message will then be used when the first validation expression fails, the second one on the second validation expression and so on.

An alternative to field level validations are form level validations defined with tag <tml:validate>. These validations need to use the TMLForm object and have no individual $E_VALUE and $P_VALUE.

The validation is executed at the time where the form data is about to be stored to some data backend, using either default action $store or the TMLScript methods tmlform.store()tmlform.storeInContent()tmlform.storeInProfile() or tmlform.storeInPortlet(). At that time the form processes all validations and collects messages of failing ones. If no validation failed the storage action is executed. The individual "storeIn..." method then returns true.

If a validation fails then the storage action is cancelled. The messages of failing validations can be put out with tag <tml:formmessages> or retrieved in TMLScript via methods like tmlform.getMessage()tmlform.hasMessages()tmlform.messages and more.

A validation may also be triggered manually without storing anything using tmlform.validate().