HTML::SuperForm::Field - HTML form field base class
package myForm::SuperDuper;
use base 'HTML::SuperForm::Field';
sub init {}
sub prepare {}
sub to_html {
my $self = shift;
my $tag = qq|For some reason this text makes|;
$tag.= qq|the field super duper|
$tag.= qq|<input type="text" name="| . $self->name . '"';
$tag.= qq| value="| . $self->value . '"';
$tag.= '/' if $self->well_formed;
$tag.= '>';
return $tag;
}
1;
This is the base class for all the HTML form field objects.
- new($form, %args), new($form, \%args),
new(%args), new(\%args)
- $form is the HTML::SuperForm object to associate
the field with. %args usually has the following
(each is also a method to access its value):
- name()
- The name of the field.
- default()
- The default value to use before data has been submitted or if the form
isn't sticky.
Other possible arguments include:
- sticky()
- Determines whether the field is sticky or not. Defaults to what the form
object's sticky flag is set to. If no form object is specified it defaults
to false.
- fallback()
- Determines whether the field's value "falls back" to the default
if the field is sticky but no data has been submitted for the field.
Defaults to what the form object's fallback flag is set to. If no form
object is specified it defaults to false.
- well_formed()
- Determines whether the HTML generated is well-formed or not. If true, a
slash is added to the end of non-container tags (i.e. <input
type="text name="my_text"/>). Attributes such as
multiple, readonly, disabled, selected, and checked are also set equal to
true values instead of being left alone (i.e. <input
type="checkbox" checked="checked"> rather than just
<input type="checkbox" checked>).
- values_as_labels(),
value_as_label()
- Determines whether the value specifed by value or values is used as a
label if no label is specified. Default is true.
- disabled()
- Determines whether the field is disabled or not.
Arguments not used by all the fields also include:
- multiple()
- Determines whether a field can have multiple values selected. Only Select
uses this feature.
- readonly()
- Determines whether a field is readonly. Used by fields such as Text and
Textarea.
- init($config)
- This method is the very first thing called in HTML::SuperForm::Field's
constructor. Subclasses of HTML::SuperForm::Field should override this
method to manipulate the parameters passed in before processing them. An
example is in HTML::SuperForm::Field::Checkbox.
- prepare()
- This method is the very last thing called in HTML::SuperForm::Field's
constructor. Subclasses of HTML::SuperForm::Field should override this
method to add extra information to the object for later use. An example of
its use is in the documentation for HTML::SuperForm under the section
EXAMPLES.
- to_html()
- This method returns the string representation of your field. When the
object is used in string context this method is called to generate the
string. Subclasses of HTML::SuperForm::Field should override this method
display a default layout. All of the basic fields that come with
HTML::SuperForm have this method, so look at them for examples. The
Counter example in HTML::SuperForm's documentation could also be
helpful.
HTML::SuperForm::Field::Text,
HTML::SuperForm::Field::Textarea,
HTML::SuperForm::Field::Select,
HTML::SuperForm::Field::Checkbox,
HTML::SuperForm::Field::Radio,
HTML::SuperForm::Field::CheckboxGroup,
HTML::SuperForm::Field::RadioGroup
John Allwine <jallwine86@yahoo.com>
Hey! The above document had some coding errors, which are explained
below:
- Around line 495:
- '=item' outside of any '=over'
- Around line 516:
- You forgot a '=back' before '=head1'