In the Webform Validation module, we have a powerful ally indeed! The basic validation functions that are built into Webform are immensely augmented by the range of possibilities exposed by Webform Validation. The module enables us to specify additional validation rules through a point-and-click interface and, in certain cases, to specify a custom error message for a particular rule.
Let us head on over to the project home page to get the module installed on our site: http://drupal.org/project/webform_validation.
Let's discover how we may utilize the Webform Validation module to extend the range of validations that we may implement on our Webforms.
15
as the Minimum number of words. Now we click on the Add rule button to save our new validation rule.Webform Validation presents us with several ready made validation options. The purpose and function of each rule type is explained underneath the respective headings on the Form validation page.
Due to variances in the way different types of components are presented and used, not all validation rules are applicable to all component types. Clearly one cannot enforce a Minimum number of selections required rule on a text field, for example. Thus each rule type description includes a list of pertinent component types which that rule can affect. While we are editing a rule, we can select one or more components against which the validation should run via the checkboxes next to the component names.
Of the validation rule options available to us, Regular expression is perhaps the hardest to come to grips with for the average user, although it is an immensely powerful tool to have. With roots in mathematical set theory, regular expression is a formal language that enables the matching, or recognizing, of patterns of characters within strings. It may be utilized to determine whether user input is correctly formatted, contains required words, has required words immediately following other required words (or phrases), and so on.
For those of us unfamiliar with regular expressions, it can seem akin to arcane magic, but any time spent learning how to utilize this tool will repay itself many times over. The Webform Validation home page recommends a visit to the online Regular Expression Library at http://regexlib.com/ to help us find useful examples of regular expressions in action.
As we build up our collection of additional validation rules we will find these listed in a table at the top of the Form validation page. Each row in the table contains links enabling us to modify or delete our rules after we have created them.
Already, our capability to validate user input beyond the standard functionality offered by Webform has been enormously extended. However, that is not all there is to it.
The developers among us will be glad to know that Webform Validation also makes available a collection of hooks which enables us to extend the module and add our own validation rules. In this way, we are able to produce site-wide Webform Validation rules as defined by our various requirements.
More information on extending this module may be found in the README.txt
file in the Webform Validation module folder, or on the project home page. We will also cover an example of custom validation in Chapter 8, Acting on Webform Submissions.
The default operation of Drupal is to validate data when it is submitted to the web server. This is called server-side validation, because the validation processes are handled by PHP programming that resides on the web server and can only occur after the data has been sent (that is, submitted) from the web browser to the server.
The Clientside Validation module (http://drupal.org/project/clientside_validation) has a Clientside Webform Validation submodule that integrates nicely with both Webform and Webform Validation to bring our validation rules to the web client (that is, the web browser being used to view our form). The effect this has is that field validation occurs immediately after the user moves away from a field and will display required error messages prior to the form being submitted. When the user returns to the field flagged as being in error and corrects their input, the error message disappears.
This type of validation is also known as Ajax form validation or real-time form validation. Clientside Validation makes use of the jQuery JavaScript library to achieve its web client effects.