Handling complicated forms can really be a pain sometimes, especially if you want to handle user errors.
The Form module can save you a lot of time and trouble, once you've learned how to use it.
Most of the time, you'll want this:
- Your form has all sorts of fields: text fields, textareas, checkboxes, radio buttons, ...
- By default, some fields are empty, and some have default values.
- Some fields are mandatory, some aren't. Some fields can only have certain values (ex: birthdate, price, ...)
And you'll probably want your form to behave like this:
- When the form is first displayed, all fields are either empty or they have a default value
- The user fills the form in and hit the submit button
- (At this point, you may want to use a few lines of javascript to catch trivial errors. But if your
form is really big, you'll probably want to catch these errors on the server side ...)
- The data is sent to the server, which analyzes it
- If the data is correct (no missing field, no wrong value, ...), everything continues normally
- In case some fields have incorrect values, you'll probably want the following:
- Redisplay the form, but keep all values that the user entered (that's the painful part ...)
- Display a message that stands out at the top of the form to notify the user that some fields need to be changed
- Display a message next to each field that has an error
We'll see how the Form module can help you do that ...
See About this document... for information on suggesting changes.