Account services

Form validation example

This form is a fully functioning example of form validation and display of error messages.

Want to join?

Press shift-key to select more than one

How is it done?

The REQUEST-method is used to determine whether the form has been submitted. If it is GET, then the form is seen for the first time, and no error messages are displayed. Otherwise the fields are validated in a script that returns an associative array (in Python called dictionary), which contains error messages keyed form field. All errors are list above the form. It makes it easy to get an overview of what is wrong, as the cost of having to look for the field below when correcting. If a field has an error, the class="error" is added to the <input/> element.