Add a User
part of a tutorial on the Dynamic Publishing
System by Karl Goldstein
This lesson introduces the form manager component of the publishing
system, which generates templated forms and handles validation and
database transactions for form submissions. The objective of this
lesson is to create a simple form to add a user to the list of sample
users. Subsequent lessons will expand on this example to illustrate
other features of the form manager.
Create the form specification
A form specification is a simple XML document that uses a standard
set of tags to describe a form and its individual elements.
Create a file named user-add.form in a test directory of
your server and enter the following specification:
As this example shows, a form specification consists of some
general properties followed by any number of form elements. In
particular pleas note:
- The dbaction element is set to insert.
- Each element maps to a column in the database table
ad_template_sample_users. The column name is assumed to be
the same as the element name. The datamap container also has
an optional column attribute that may be used with the name
of the form element and column are different. The user_id
element is marked as a "parent" key, since it is the primary key for
the table.
- The hidden form element user_id has a default value that
is set based on a database query.
- All elements except for user_id use the default widget, which
is a text input box. They are also of the default data type, which is
text.
- The city and state elements are marked as optional.
They may be left blank by the user. The other elements by default
are expected to be required.
- The state element has an additional attribute
attribute. This may be used to add arbritary additional attributes
to the input or select tag, such as the maxlength
attribute or JavaScript event handlers, which may be used for
presubmission validation.
Create the form template
To embed the form into any page using a standard form template, you
can use the formtemplate tag to autogenerate the form
using a standard sitewide template:
View the form
karlg@arsdigita.com