Return CGI Library
Return Form Handling
This gadget supports two methods of enforcing which fields can not be empty.
The first method is the simplest to do, but doesn't produce very friendly error messages. To use this method, simply include a
hidden field called MANDATORY with a value that lists all the fields you want to force the browser to fill in before submitting
(separate the field names with spaces).
example:
<input type="hidden" name="MANDATORY" value="FROM TO SUBJECT" />
Here it is in action:
If you tried that, you might have noticed that the error messages aren't exactly user friendly.
The solution is to use the second method:
A better solution is to specify your own error message for each field. You can do this by specifying a hidden field named after
the variable you want to make mandatory, but with a "mandatory-" prefix.
Ex. To make the FROM variable mandatory, and to set the error message to "You must specify your return e-mail address."
<input type="hidden" name="mandatory-FROM"
value="You must specify your return e-mail address." />
This starts to get a little tricky when you add HTML to your error message :-(. Old and new browsers disagree about when tags
without proper quotes end. With the new browsers, you can simply drop all the quotes inside your error message and it will work,
but you'll seriously confuse the older browsers (even Netscape 1).
The proper solution is to replace all the <, >, and " characters with their "tag" equivalents... (e.g. < becomes <
> becomes > and " becomes ")
Expressing this becomes complicated... Cut this example from the screen and NOT the "view source".
To get:
value="You <b>must</b>
enter your e-mail address."
you'll have to write:
value="You <b>must</b> enter your e-mail address."
However the result is worth the effort, especially when you add in the
ERRORFTR and ERRORHDR values (which can set a header and a footer for the error page):
If there are multiple "mandatory-" fields missing, then all the errors will be displayed separated by <P> tags.
At some point you will have to ask yourself "How fancy do I want to get?" ... the good news is that it's your choice... :-).
|