A user creates a Docbase record by means of a web form. The form isn’t served statically, though. It’s generated on the fly from a template. After all that discussion in the last chapter about the virtues of dynamically generated but statically served pages, why should we generate this form? The technique helps us to constrain inputs, enforce controlled vocabularies, and divide the responsibility for completing different parts of the form among different people.
Example 6.1 shows the template for the ProductAnalysis input form.
Example 6-1. ProductAnalysis Input Form Template
<html> <head> <title>Product Analysis Report Form</title> </head> <body> <center><b>Product Analysis Report Form</b></center> <form method="post" action="!ACTION!
"> <table cellpadding="4"> <tr> <td align="right"><b>Assignment Date</b></td> <td align="left">|assigndate|
</td> </tr> <tr> <td align="right"><b>Due Date</b></td> <td align="left">~duedate~
</td> </tr> <tr> <td align="right"><b>Analyst</b></td> <td align="left">~analyst~
</td> </tr> <tr> <td align="right"><b>Company</b></td> <td align="left">~company~
</td> </tr> <tr> <td align="right"><b>Product</b></td> <td align="left">~product~
</td> </tr> <tr> <td align="right"><b>Title</b></td> <td align="left"><input name="title" size="40"></td> </tr> <tr> <td align="right"><b>Summary</b></td> <td align="left"><textarea name="summary" rows="2" cols="50" wrap="virtual"></textarea></td> </tr> <tr> <td align="right"><b>Full report</b></td> <td align="left"><textarea name="fulltext" rows="3" cols="50" wrap="virtual"></textarea></td> </tr> <tr> <td align="right"><b>Contact info</b></td> <td align="left"><textarea name="contact" rows="3" cols="50" wrap="virtual"></textarea></td> </tr> </table> <p><center><input type="submit" value="submit"></center></p> </form> </body> </html>
I wrote this template by hand, but you could also produce it using an HTML editor. Either way, the crucial idea here is to separate the concerns of a designer, who worries about the form’s content and appearance, from the concerns of an implementer, who wires the form to a scripted handler. In this scenario, the form’s author and its implementer need only share a common vocabulary of markers, or replaceable elements, that invoke special functions when the template is processed to produce an actual HTML form.
There are three kinds of replaceable elements. The code that processes the template looks for patterns that match these marked elements and replaces them as described in Table 6.1.
Table 6-1. Docbase Input Template: Marked Elements and Replacements