|
Apache::Wyrd::Input - Form Input Wyrds |
Apache::Wyrd::Input - Form Input Wyrds (scalar)
<BASENAME::Input type="text" name="foo" flags="required" />
<BASENAME::Input type="textarea" name="desc" height="100" width="100">
This is the default text
</BASENAME::Input>
<BASENAME::Input type="hidden" name="name" value="lenore" />
<BASENAME::Input type="password" name="name" size="10" />
sub _startup_integer {
my ($self, $value, $params) = @_;
$self->{'_datum'} ||=
Apache::Wyrd::Datum::Integer->new($self->{'value'}, $params);
$self->{'_template'} ||= '<input type="text" name="$:name" ' .
'value="$:value"?:size{ size="$:size"}?:id{ id="$:id"}' .
'?:readonly{ readonly}>';
$self->{'_smart_type'} = 'text';
}
<BASENAME::Input type="integer" default="1" name="counted" />
This is the base class for Input objects, which are tracked and affected by the Apache::Wyrd::Form (Form) objects that enclose them. The base Input object is meant to replace, in most cases, the input HTML objects:
For these, set the type attribute to text, password, textarea,
and hidden respectively. Another hybrid input is plaintext, which
both shows the text and includes it in the form as a hidden input. For
other input types, such as radiobuttons, checkboxes, selection sets,
etc., see Apache::Wyrd::Input::Set.
The Input does it's work in the _format_output phase. If given a
type of ``foo'', it will first attempt to match it to one of the standard
types, then look for a startup_foo method and if it finds it, will call
the method. This is to allow derived Input objects to initialize
builtins, if needed, without re-implementing the whole _format_output
method.
Any derived startup_foo method should, for completeness, set the _datum
attribute to a Datum object appropriate to the type, put together a
template for the input appropriate to the expected output, and if the
Apache::Wyrd::Interfaces::SmartInput interface is to be used, set the
_smart_type attribute to the appropriate one for the template. See the
SYNOPSIS for an example startup routine for integer types.
For entry pages to Forms or any other state where the enclosing Form cannot determine the initial value of an input, the Input will try the current value it would be getting from a submission now (typically by using a CGI parameter of the same name), any previous submissions (in this form sequence) of variables of the same name, and lastly the ``default'' value before giving up and initializing to null.
Apache::Wyrd::Interfaces::SmartInput interface.
(format: (returns) name (arguments after self))
name, type, value, description, param (void)name, type, value,
description, and param. The param attribute is optional for
Inputs which might need to use another name than the CGI variable of
their associated HTML input. [No, I can't think of a reason why they
should, but any absurdity is possible given a sufficient quantity of
spaghetti]
Note that the value call gets the current value of the input from the
underlying _datum object, and not from it's temporary storage under
the _value attribute. This allows the Datum to be independent of the
temporary value of the Input.
Apache::Wyrd::Form, typically) through the set method.
set accepts a value, which is converted to the appropriate type (arrayref, scalar, etc.) to safely pass the next test, which is the _check_param internal method. If _check_param returns a null result, it is assumed to have failed and the appropriate error calls are made, setting error flags in the parent via the parent's register_errors and register_error_messages.
In the parent, register_errors is assumed to process the triggers and register that at least one error has occurred in submitting it's inputs. register_error_messages is called separately, as there may not be a one-to-one correspondence between what the Input should warn the user about and what it considers an error.
The no_fail flag prevents the errors from registering at all, while the quiet flag will suppress only the error messages.
However, pass or fail, a call to the _datum object will occur with the set call, and presumably, the Datum class will know how to deal with that. For it's own purposes, however, the value will be temporarily stored by the Input, and HTML esacaped if the escape flag is set.
Apache::Wyrd::Input::Opt) in order to determine what options to give
to the datum object. If this value is already a hashref or arrayref, it
does no further processing. Otherwise it attempts to separate the words
of the options attribute, using an optional regexp under the ``delimiter''
attribute.
A shorthand for adding this method to an item is the description attribute, which will be prepended to the error string if an error occurs.
the values stored in the _errors and _error_messages registers can be accessed read_only through the errors and error_messages methods, as demonstrated by the Form object.
errors (void)Apache::Wyrd::Form object for the
Apache::Wyrd::ErrTag objects to detect (see documentation for those
modules).
error_messages (void)_escape (scalar)_escape method is a utility for escaping the data in an HTML
text-type input in order to avoid formatting errors. The default is to
only escape quotes and ampersands by encoding them as the appropriate
entity.
_escape (scalar)_unescape method should reverse-mirror the _escape method exactly.
_template_foo (scalar)_template methods should provide an
Apache::Wyrd::Interfaces::Setter-style template for a given input.
Built-in templates are text, textarea, password
Reserves the _format_output and _generate_output methods. Also
reserves the final_output method.
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::Input - Form Input Wyrds |