|
Apache::Wyrd::Form - Interactive HTML form Wyrd |
Apache::Wyrd::Form - Interactive HTML form Wyrd
NONE
The Apache::Wyrd::Form (Form) object provides the core mechanism for
processing fill-in forms.
The Form requires one or more Apache::Wyrd::Form::Template objects
(Templates) which provide, on the same page/url/Location, the pages
which make up the complete form.
By default, the form will process these Templates in order, starting
with the first enclosed Template in order of appearance in the HTML
text, and ending with the last, accepting each set of input from the
browser and moving on to the next. On submission of the last page, the
form finalizes the process by calling the _submit_data method. This
way, a large amount of data can be entered in subsequent browser-pages
as if they were the same page and submitted only when the full requisite
of data is accumulated. Additionally, there are methods available for
conditionally moving between Templates in order to include or exclude a
section of the Template-set or range of requirements.
The form maintains the state of the information between Template pages, accumulating them in the (reserved) _variables attribute. If inputs/controls in later Templates have the same name as those in earlier ones, the values submitted in the earlier ones will be the initial values of the later.
Forms have three classes of children: Inputs, Views, and Errors. Forms
track the value of and operate on Inputs, meaning
Apache::Wyrd::Inputs or derived classes of Apache::Wyrd::Input.
Form::View (View) objects show a snapshot of the current state of the
form, as a preview, and Form::ErrTag and Form::ErrField objects
(Error Flags) indicate on the page which Inputs have illegal values for
the requirements of the form. Dev. Note: Although they are all
enclosed in a Form::Template Wyrd, all these elements are actually
direct children of the Form, because the Template enclosing them becomes
the literal body of the form for the browser-server transaction at that
point in the sequence. (Form objects use a method called _reload_self
to do this.)
Input values can also be initialized via CGI by passing values (in a get
or post request) to the Form. There is also a pair of explicit
initializers, Apache::Wyrd::Form::Preload and
Apache::Wyrd::Form::Defaults, which are placed inside Templates to
initialize the values of inputs within that Template. Internally, the
_preload_inputs method can be overridden (defined in a subclass) to do
the same, and yet another method _extra_preloads can be overridden to
preload specific input values.
The Form calls the set method of each of it's Inputs, passing a value
to the Input which is derived (in order of priority) by checking to see
if the input can provide a current_value, seeing if it has a method
defined for that purpose, _param_process_foo where ``foo'' is the name
of the parameter, or lastly, by checking the CGI environment for the
value. Dev. Note: Inputs also have a priority by which they attempt to
establish default values for themselves based on defaults or the current
CGI environment if the Form is unable to determine one for them, as is
the case on Form entry pages. See the documentation for
Apache::Wyrd::Input.
Internally, the form also manipulates the CGI environment to make the use of image-buttons more convenient. It searches for CGI parameters by the name of foo.x and sets value of the parameter action to ``foo''. This allows to set an action parameter simply by naming the image button to the name of the action you would like it to perform. For example, the following input will cause an Apache::Wyrd::Form object to set the value of the CGI parameter action to ``cancel'':
<input type="image" src="/images/cancel.gif" name="cancel">
Before advancing to the next Template in the sequence, the form will
check every input in turn to see if it has returned an error. Errors
are compiled, and if they number more than zero, the submitted Template
will be reloaded, setting any Error Flag triggered by the Input. If
there are no errors, the Form moves on to the next Template. If there
are no more templates, it submits all its accumulated data via the
_submit_data method.
No matter which template is the current one, the Form will also complete
the transaction by setting any placemarkers inside the template which
match the name of one of the _globals keys. By so doing, the
programmer can set a global at any point in the form handling system and
expect that global to show in it's placemarked area in the HTML of the
form.
Among the standard globals is the error_block global, which represents where to put the block of error messages on the page of the form. In other words if $:error_block does not appear on the template, there will be no error_block shown on the form.
Apache::Wyrd::Form::Preload object.
Because of the complexity of the Apache::Wyrd::Form object,
explanations of these internal attributes are provided to aid
development of subclasses.
Apache::Wyrd::Interfaces::Setter-style
placemarkers set to these values.
(format: (returns) name (arguments after self))
drop_var (scalar)insert_error (array)insert_error_messages (array[ref])_dump_errors method.
register_form (Apache::Wyrd::Form::Template)Apache::Wyrd::Form::Template to build the form sequence. Also notes
the action attribute of the template, which can override the default or
given action of the Form.
register_errors (Apache::Wyrd::Input)insert_error, except the argument is an Input object who's
errors are inserted.
register_error_messages (Apache::Wyrd::Input)insert_error_messages, except the argument is an object who's
(possibly multiple) errors are inserted.
register_input (Apache::Wyrd::Input)Apache::Wyrd::Input
register_errortag (Apache::Wyrd::ErrTag)Apache::Wyrd::ErrTag or Apache::Wyrd::ErrField.
register_view (Apache::Wyrd::ErrTag)Apache::Wyrd::Form::View.
set_var (scalar)
_interpret_action (void)_format_error (scalar)_format_error_block to
format the error message on the page. These are compiled into a block
during the _format_output phase. Default behavior is to return the
error as an HTML line-item.
_format_error_block (scalar)_format_error_block to format the error message on the page. Default
behavior is to return the error as an HTML unordered list with the text:
``The following problems were found:'' and ``Please correct the items
marked before continuing'' around it. The default behavior assumes the
CSS style .error is defined to mark errors. See
Apache::Wyrd::ErrField.
_prep_submission (void)_submit_data method is used, this provides a hook for
altering the data prior to submitting it.
_submit_data (void)_prep_preloads (void)_extra_preloads (void)_activate_widgets (void)_check_form (void)_check_reset (void)_check_form (void)_storage_template (void)_submitted (void)_proof_of_submit (void)
The Form object also reserves the methods _dump_errors, _fire_triggers, _unpack_data, _pack_data, _preload_inputs, _check_inputs, _check_errors, _reload_form, _get_value, _wrap_form, _current_marker, register_child, and _set_children.
Reserves the _setup, the _format_output, AND the _generate_output method. Subclassing is done via the other hooks, above.
Barry King <wyrd@nospam.wyrdwright.com>
Copyright 2002-2004 Wyrdwright, Inc. and licensed under the GNU GPL.
See LICENSE under the documentation for Apache::Wyrd.
|
Apache::Wyrd::Form - Interactive HTML form Wyrd |