HTML::SuperForm(3)
π HTML::SuperForm π β the HTML::SuperForm(3) page, part 1
okay so bestie, you found the manual for HTML::SuperForm and lemme tell you, this thing slaps. let's get into it π
β¨ NAME β¨
HTML::SuperForm β HTML form generator π
like. it generates HTML forms. that's the whole serve. iconic behavior honestly.
πΈ SYNOPSIS πΈ
here's the tea, in code form:
use HTML::SuperForm;
use Apache::Constants qw(OK);
sub handler {
my $r = shift;
my $form = HTML::SuperForm->new($r);
my $text = $form->text(name => 'text',
default => 'Default Text');
my $textarea = $form->textarea(name => 'textarea',
default => 'More Default Text');
my $select = $form->select(name => 'select',
default => 2,
values => [ 0, 1, 2, 3],
labels => {
0 => 'Zero',
1 => 'One',
2 => 'Two',
3 => 'Three'
});
my $output = <<"END_HTML";
<html>
<body>
<form>
Text Field: $text<br>
Text Area: $textarea<br>
Select: $select
</form>
</body>
</html>
END_HTML
$r->content_type('text/html');
$r->send_http_header;
$r->print($output);
return OK;
}
OR
#!/usr/bin/perl
my $form = HTML::SuperForm->new();
my $text = $form->text(name => 'text',
default => 'Default Text');
my $textarea = $form->textarea(name => 'textarea',
default => 'More Default Text');
my $select = $form->select(name => 'select',
default => 2,
values => [ 0, 1, 2, 3],
labels => {
0 => 'Zero',
1 => 'One',
2 => 'Two',
3 => 'Three'
});
my $output = <<"END_HTML";
<html>
<body>
<form>
Text Field: $text<br>
Text Area: $textarea<br>
Select: $select
</form>
</body>
</html>
END_HTML
print "Content-Type: text/html\n\n";
print $output;
two whole vibes: the mod_perl handler way, OR the plain ol' script way. pick your fighter π₯
π¦ DESCRIPTION π¦
So. Used in its basic form, this module gives you an interface for generating basic HTML form elements β much like HTML::StickyForms does. the main difference? HTML::SuperForm returns HTML::SuperForm::Field objects instead of plain HTML. which is lowkey huge, because it means way more flexibilty when you're generating forms for a complex application. β¨
To get the most out of this module, use it as a base (Super) class for your own form object that generates your own custom fields. if you don't use it that wayβ¦ I guess there's really nothing Super about it π. Examples are shown later in the document.
The interface was designed with mod_perl and the Template Toolkit in mind, but it works equally well in any cgi environment. we love range π
π METHODS π
π CONSTRUCTOR π
new($r, $field_object),new($r),new()β Creates a newHTML::SuperFormobject.- If
$argis an Apache object then anApache::Requestobject will be created from it to retrieve the parameters. If you don't haveApache::Requestinstalled then it behaves as if$argis undef. π - If
$argis anApache::Requestobject, CGI object or a hash reference, then it is used to retrieve the parameters. If no argument is given or the argument isn't an instance or subclass of the objects mentioned above then the parameters are retreived through the environment variables. If called in a non-cgi environment, no stickyness is applied. - It is recommended to use CGI or
Apache::Requestbecause the parameter parsing included inHTML::SuperFormdoesn't include the complexities that CGI andApache::Requesttake in to account and only works withapplication/x-www-form-urlencodedforms. > β οΈ yes bestie that's a real limitation, read it twice. - If you pass
$field_object, thenHTML::SuperFormwill use that object instead ofHTML::SuperForm::Field. Seefield_object()below andHTML::SuperForm::Fieldfor more on this. π«Ά
- If
π ACCESSORS AND MUTATORS π
These methods get and set values contained in the form object.
set_sticky($flag),sticky($flag)set_sticky(),sticky()β Returns the state of the sticky flag. If an argument is given the sticky flag is set to that value. The sticky flag defaults to false. The flag determines whether the form uses the default values (false) or submitted values (true). πfallback($flag),fallback()β Sets whether the form's fields "fall back" to their default values if the form is sticky and no data has been submitted for those fields. Defaults to false.values_as_labels($flag),values_as_labels()β Returns the state of thevalues_as_labelsflag. If an argument is given flag is set to that value. Thevalues_as_labelsflag defaults to true. The flag determines whether select fields, checkboxes and radio buttons use their values as labels if no labels are given.well_formed($flag),well_formed()β Returns the state of thewell_formedflag. If an argument is given flag is set to that value. Thewell_formedflag defaults to true. The flag determines whether the HTML generated is also well-formed XML. β¨start_form(%args),start_form(\%args)β Returns the starting HTML form tag with all the attributes you pass it. These are some arguments you might give (each is also a method that returns its value):name()β The name of the form.method()β The method in which the form is submitted (GET or POST). The default is POST.
If the method set in start_form() equals the method that is detected from the current request then the form is set to sticky. π
action()β The url to which the form is submitted.- Any other attribute you specify can be accessed by calling its method (i.e. if you pass in (
target => 'newWindow',onSubmit => BAqCheckForm()),$form->targetwill return'newWindow', and$form->onSubmitwill returnBAqCheckForm()). The names are case sensitive so be consistent. π fr fr, case sensitive.
no_of_fields($name)β Returns the number of fields which have the given name.param(%args),param(\%args),param($name)β Gets the parameters with name$nameor sets parameters with names equal to the keys of%argsand values equal to the values of%args. The parameters are used by the form object as if they were submitted values.exists_param($name)β Returns true if a value exists for the parameter named$name. Otherwise, returns false.params()β Returns a reference to a hash of the submitted parameters.
π GET AND SET π
Since I intended HTML::SuperForm's main use to be as a base class, I made these methods so subclasses can store information within the object without worrying about overriding important keys in the object. thoughtful queen behavior π
set(%args),set(\%args)β Stores infomation in form for later retrieval byget().get(@keys)β When called in list context, returns an array of values that were previously stored withset(). When called in scalar context, returns a reference to an array of values or, if only one key is given, the corresponding single value.
π§ INTERNAL METHODS π§
You probably won't ever need to use these methods unless you are in a subclass of HTML::SuperForm or HTML::SuperForm::Field. iykyk β if you know, you know π
set_default(%args),set_default(\%args)β Sets default values in form for each key/value pair in%args.add_default(%args),add_default(\%args)β Adds default values to form for each key/value pair in%args.field_object()β Returns the field object (the string, not an actual object) that is the base class of all the field objects.
This will almost always be HTML::SuperForm::Field. If you subclass HTML::SuperForm::Field (as a replacement for HTML::SuperForm::Field, not as a field like Text or Select etc.) then you have to tell the form object to use it. Also, if you do that, make sure you write your own field classes (Text, Select etc.). Consult documentation for HTML::SuperForm::Field for more on this. π«Ά
β FIELD METHODS β
These methods return objects with their string operators overloaded to output HTML. which is the part that's actually iconic, no cap.
text(%args),text(\%args)β Returns anHTML::SuperForm::Field::Textobject.textarea(%args),textarea(\%args)β Returns anHTML::SuperForm::Field::Textareaobject.hidden(%args),hidden(\%args)β Returns anHTML::SuperForm::Field::Hiddenobject.password(%args),password(\%args)β Returns anHTML::SuperForm::Field::Passwordobject.select(%args),select(\%args)β Returns anHTML::SuperForm::Field::Selectobject.checkbox(%args),checkbox(\%args)β Returns anHTML::SuperForm::Field::Checkboxobject.radio(%args),radio(\%args)β Returns anHTML::SuperForm::Field::Radioobject.checkbox_group(%args),checkbox_group(\%args)β Returns anHTML::SuperForm::Field::CheckboxGroupobject.radio_group(%args),radio_group(\%args)β Returns anHTML::SuperForm::Field::RadioGroupobject.submit(%args),submit(\%args)β Returns anHTML::SuperForm::Field::Submitobject.
β¦to be continued, bestie π
π§ͺ EXAMPLES π§ͺ
okay bestie, this is the glow-up section π This example shows how to make a form object that can generate a counter field along with all the other basic fields. And what even is a counter field? It's literally a text field, an increment button, and a decrement button β that's the whole trio, no cap π If you wanna go deeper on field inheritance, go read the documentation for HTML::SuperForm::Field, they explain it better than I ever could π«Ά
package myForm;
use strict;
use myForm::Counter;
use base 'HTML::SuperForm';
sub counter {
return myForm::Counter->new(@_);
}
sub javascript {
my $js = <<END_JAVASCRIPT;
<script language="JavaScript">
function Increment(field) {
field.value++;
}
function Decrement(field) {
field.value--;
}
</script>
END_JAVASCRIPT
return $js;
}
1;
package myForm::Counter;
use strict;
use base 'HTML::SuperForm::Field';
use HTML::SuperForm::Field::Text;
sub prepare {
my $self = shift;
my $form_name = $self->form->name;
my $field_name = $self->name;
my $js_name = "document.$form_name.$field_name";
my $text = HTML::SuperForm::Field::Text->new(name => $self->name, default => $self->value, size => 4);
$self->set(text => $text);
$self->set(inc => qq|<a style="cursor: pointer" onmouseup="Increment($js_name)"><img src="/icons/up.gif" border=0></a>|);
$self->set(dec => qq|<a style="cursor: pointer" onmouseup="Decrement($js_name)"><img src="/icons/down.gif" border=0></a>|);
}
sub inc {
my $self = shift;
return $self->get('inc');
}
sub dec {
my $self = shift;
return $self->get('dec');
}
sub text {
my $self = shift;
return $self->get('text');
}
sub arrows_right {
my $self = shift;
my ($text, $inc, $dec) = $self->get('text', 'inc', 'dec');
my $tag = "<table>\n";
$tag .= qq| <tr>\n|;
$tag .= qq| <td align="center">$text</td>\n|;
$tag .= qq| <td align="center">$inc<br/>$dec</td>\n|;
$tag .= qq| </tr>\n|;
$tag .= "</table>\n";
return $tag;
}
sub arrows_left {
my $self = shift;
my ($text, $inc, $dec) = $self->get('text', 'inc', 'dec');
my $tag = "<table>\n";
$tag .= qq| <tr>\n|;
$tag .= qq| <td align="center">$inc<br/>$dec</td>\n|;
$tag .= qq| <td align="center">$text</td>\n|;
$tag .= qq| </tr>\n|;
$tag .= "</table>\n";
return $tag;
}
sub default_layout {
my $self = shift;
my ($text, $inc, $dec) = $self->get('text', 'inc', 'dec');
my $tag = "<table>\n";
$tag .= qq| <tr><td align="center">$inc</td></tr>\n|;
$tag .= qq| <tr><td align="center">$text</td></tr>\n|;
$tag .= qq| <tr><td align="center">$dec</td></tr>\n|;
$tag .= "</table>\n";
return $tag;
}
sub to_html {
my $self = shift;
my $tag = $self->default_layout;
return $tag;
}
1;
ngl this might seem complex π but the way that using it like this gives you the following functionality? iconic. periodt β¨
package myHandler;
use strict;
use myForm;
use Apache::Constants qw(OK);
use Template;
sub handler($$) {
my $self = shift;
my $r = shift;
my $form = myForm->new($r);
my $tt = Template->new(INCLUDE_PATH => '/my/template/path');
my $output;
$tt->process('my_template.tt', { form => $form }, \$output);
$r->content_type('text/html');
$r->send_http_header();
$r->print($output);
return OK;
}
1;
and then the template file itself, my_template.tt: πΈ
<html>
<head>
<title>Flexibility with HTML::SuperForm</title>
[% form.javascript %]
</head>
<body>
[% form.start_form %]
Default Counter Layout: [% form.counter(name => 'counter1', default => 0) %] <br/>
Counter with increment/decrement buttons on the left: [% form.counter(name => 'counter2', default => 0).arrows_left %] <br/>
Counter with increment/decrement buttons on the right: [% form.counter(name => 'counter3', default => 0).arrows_right %] <br/>
Counter with multiple increment/decrement buttons wherever you want: <br/>
[% counter = form.counter(name => 'counter4', default => 0) %]
<table>
<tr><td>[% counter.inc %]</td><td></td><td>[% counter.inc %]</tr>
<tr><td></td><td></td>[% counter.text %]<td></tr>
<tr><td>[% counter.dec %]</td><td></td><td>[% counter.dec %]</tr>
</table>
[% form.submit %]
[% form.end_form %]
</body>
</html>
π SEE ALSO π
go read your sisters, they're all slaying π
HTML::SuperForm::FieldHTML::SuperForm::Field::TextHTML::SuperForm::Field::TextareaHTML::SuperForm::Field::SelectHTML::SuperForm::Field::CheckboxHTML::SuperForm::Field::RadioHTML::SuperForm::Field::CheckboxGroupHTML::SuperForm::Field::RadioGroup
π TODO π
the to-do list, aka the "someone please" list π₯Ί
- Document its usage for fully.
- Give more examples.
π AUTHOR π
John Allwine <jallwine86@yahoo.com> β the mastermind, the main character, the one who wrote this whole thing π
βοΈ COPYRIGHT βοΈ
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
and that's a wrap, bestie πβ¨ this whole page comes to you courtesy of perl v5.42.0, dated 2025-07-25 β HTML::SuperForm(3), go build something cute with it π¦π
π¦ where this page comes from
- fedora 43: perl-HTML-SuperForm 1.09-45.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms