There are many ways to display and process HTML forms with Cheetah. But basically, all form processing involves two steps.
The second step may involve choosing between several templates to fill (or several servlets to redirect to), or a big if-elif-elif-else construct to display a different portion of the template depending on the situation.
In the oldest web applications, step 1 and step 2 were handled by separate objects. Step 1 was a static HTML file, and step 2 was a CGI script. Frequently, a better strategy is to have a single servlet handle both steps. That way, the servlet has better control over the entire situation, and if the user submits unacceptable data, the servlet can redisplay the form with a "try again" error message at the top and and all the previous input filled in. The servlet can use the presence or absence of certain CGI parameters (e.g., the submit button, or a hidden mode field) to determine which step to take.
One neat way to build a servlet that can handle both the form displaying and form processing is like this:
VALUE=
attribue.
Place another placeholder next to each field, for that field's error
message.
$processFormData
method call.
#extend
s. (Or
if it's a simple method, you can define it in a #def
.) The method
should:
$processFormData
.
$processFormData
.
$processFormData
.
FunFormKit
is a third-party Webware package that makes it easier to
produce forms and handle their logic. It has been successfully been used with
Cheetah. You can download FunFormKit from
http://colorstudy.net/software/funformkit/ and try it out for yourself.