Validation of forms

Even though a form may represent an out-of-place editor of the constrained variables in a database, it can be regarded as an in-place editor of a set of unconstrained "temporary" variables. They need to be unconstrained to allow editing to take place.

Since they are unconstrained, they can be given erroneous values. The application needs to help the user edit the data in the form to correct the errors.

It's not realistic for an application to simply catch integrity constraint violation exceptions when an attempt is made to apply a transaction after hitting apply and a generic message box appears saying "Sorry, there was an error somewhere, try again".

A user can't be expected to repeatedly submit a form until it works, without feedback.

Validation when user presses submit button

One approach is to perform validation when the user submits data via the submit button. The validation is executed and if any errors are found, feedback is returned and displayed to the user.

validation-on-submit

The disavantage is that users only learn about errors after they submit the form. See Web Form Validation: Best Practices and Tutorials.

Instant validation feedback

For a better user experience, it is better to provide instant feedback as the user enters the information, so the user does not have to complete a form and hit submit before being informed of a mistake.

dialog-format-error

Ideally the submit button won't be enabled until all the data on the form has been entered correctly.