[Zope] mid-level architecture question -- populating forms

Thomas B. Passin tpassin@mitretek.org
Mon, 29 Apr 2002 15:37:00 -0400


[Dennis Allison]

> I am putting together a site with that accesses and updates a database.
> The essential structure is this:
>
> the web-user is presented with a form and provides enough information for
> the web application to find the desired information in the data base.
> This key information is passed to a External Method that accesses the data
> base and determine which of a number of forms are needed to manage the
> update.
>
> The External Method then has a number of choices vis-a-vis how to publish
> the form.   Based on the key provided by the application and the data in
> the database, it can computed the name of a static form.  It can then
>
> 1) construct a URL for the form with parameters to fill in the
> blanks, e.g.,  specialised_form_1?field1=somedata&field2=moredata
> and so forth.  I'm not sure how one would invoke this as I suspect
> getitem() would be confused.
>
> 2) evaluate the data values and put them in the REQUEST object, then
> pass down the string 'specialized_form' to the page where the form is
> to appear, generate the form with a <dtml-var expr="getitem(form-name,1)">
> and have the form look up the fill-in-the-blanks data in the REQUEST
> object.
>
> 3) generate the form on the fly (probably from a home-grown template) and
> fill in the data directly.
>

Use an external method to compute and a page template to compose the HTML.
That's the best rule.  So consider having your external method return a
dictionary of name:value pairs for the form that the user will eventually
see.  Then create the HTML page using DTML based on the dictionary returned
by the external method.  Don't use the external method to create HTML - DTML
is better for that.  You shouldn't have to stuff them into the REQUEST
object at all.

Cheers,

Tom P