|
HTML::StickyForms - HTML form generation for CGI or mod_perl |
HTML::StickyForms - HTML form generation for CGI or mod_perl
# mod_perl example
use HTML::StickyForms; use Apache::Request;
sub handler{
my($r)=@_;
$r=Apache::Request->new($r);
my $f=HTML::StickyForms->new($r);
$r->send_http_header;
print
"<HTML><BODY><FORM>",
"Text field:",
$f->text(name => 'field1', size => 40, default => 'default value'),
"<BR>Text area:",
$r->textarea(name => 'field2', cols => 60, rows => 5, default => 'stuff'),
"<BR>Radio buttons:",
$r->radio_group(name => 'field3', values => [1,2,3],
labels => { 1=>'one', 2=>'two', 3=>'three' }, default => 2),
"<BR>Single checkbox:",
$r->checkbox(name => 'field4', value => 'xyz', checked => 1),
"<BR>Checkbox group:",
$r->checkbox_group(name => 'field5', values => [4,5,6],
labels => { 4=>'four', 5=>'five', 6=>'six' }, defaults => [5,6]),
"<BR>Password field:",
$r->password(name => 'field6', size => 20),
'<BR><INPUT type="submit" value=" Hit me! ">',
'</FORM></BODY></HTML>',
;
return OK;
}
This module provides a simple interface for generating HTML <FORM> fields, with default values chosen from the previous form submission. This module was written with mod_perl in mind, but works equally well with CGI.pm, including the new 3.x version.
The module does not provide methods for generating all possible form fields, only those which benefit from having default values overridden by the previous form submission. This means that, unlike CGI.pm, there are no routines for generating <FORM> tags, hidden fields or submit fields. Also this module's interface is much less flexible than CGI.pm's. This was done mainly to keep the size and complexity down.
new($req)undef or '', the object created will behave as if a request
object with no submitted fields was given.
set_sticky([BOOL])This method is called by the constructor when a form object is created, so it
is not usually necessary to call it explicitly. However, it may be necessary to
call this method if parameters are set with the param() method after the
form object is created.
trim_params()values_as_labels([BOOL])values_as_labels attribute. This
attribute determines what to do when a value has no label in the
checkbox_group(), radio_group() and select() methods. If this attribute
is false (the default), no labels will be automatically generated. If it is
true, labels will default to the corresponding value if they are not supplied
by the user.
If an argument is passed, it is used to set the values_as_labels attribute.
well_formed([BOOL])well_formed attribute. This
attribute determines whether to generate well-formed XML, by including the
trailing slash in non-container elements. If this attribute is false, no
slashes are added - this is the default, since some older browsers don't
behave sensibly in the face of such elements. If true, all elements will
be well-formed.
If an argument is passed, it is used to set the well_formed attribute.
text(%args)"text". All arguments
are used directly to generate attributes for the tag, with the following
exceptions:
"text"
new(). The value used will have all HTML-special
characters escaped.
password(%args)text(), but generates a "password" type field.
textarea(%args)checkbox(%args)"checkbox" type <INPUT> tag. All arguments are
used directly to generate attributes for the tag, except for:
checkbox_group(%args)"checkbox" type <INPUT> tags. If called in
list context, returns a list of tags, otherwise a single string containing
all tags. All arguments are used directly to generate attributes in each tag,
except for the following:
"checkbox".
values_as_labels attribute.
radio_group(%args)checkbox_group(), but generates "radio" type tags.
select(%args)MULTIPLE attribute is set.
values_as_labels attribute.
Peter Haworth <pmh@edison.ioppublishing.com>
|
HTML::StickyForms - HTML form generation for CGI or mod_perl |