HTML-Template-Associate-FormField
view release on metacpan or search on metacpan
lib/HTML/Template/Associate/FormField.pm view on Meta::CPAN
($ENV{MOD_PERL} && isa $query, 'SCALAR') ? do { return $query }:
$type eq 'HASH' ? do { return _const_param($query) }:
! (isa $query, 'HASH') ? do { $query= {}; return _const_param($query) }:
! $query->can('param') ? do { return _const_param($query) }:
do { return $query };
}: do { $query= {}; return _const_param($query) };
}
sub _const_param {
my $query= shift || {};
HTML::Template::Associate::FormField::Param->new($query);
}
sub __startform {
my($af, $attr)= @_;
$attr->{enctype}= CGI->MULTIPART
if ($attr->{enctype} && $attr->{enctype}=~/[Uu][Pp][Ll][Oo][Aa][Dd]/);
my $form= startform($attr);
$form.= $af->hidden->get if $af->hidden->exists;
return $form;
}
sub __form { &__startform }
sub __start_form { &__startform }
sub __start_multipart_form {
my($af, $attr)= @_;
my $form= start_multipart_form($attr);
$form.= $af->hidden->get if $af->hidden->exists;
return $form;
}
sub __multipart_form { &__start_multipart_form }
sub __start_upload_form { &__start_multipart_form }
sub __upload_form { &__start_multipart_form }
sub __opt_multipart_form {
my($af, $attr)= @_;
my $form= start_multipart_form($attr);
$form=~s/(?:<[Ff][Oo][Rr][Mm]\s+|\s*>\n?)//g;
return $form;
}
sub __opt_upload_form { &__opt_multipart_form }
sub __opt_form {
my($af, $attr)= @_;
my $form= startform($attr);
$form=~s/(?:<[Ff][Oo][Rr][Mm]\s+|\s*>\n?)//g;
return $form;
}
sub __endform { q{</form>} }
sub __end_form { &__endform }
sub __hidden_out { shift->hidden->get }
sub __hidden_field { CGI::hidden(&_proc_value) }
sub __hidden { CGI::hidden(&_proc_value) }
sub __textfield { textfield(&_proc_value) }
sub __text { &__textfield }
sub __filefield { filefield(&_proc_value) }
sub __file { &__filefield }
sub __password_field { password_field(&_proc_value) }
sub __password { &__password_field }
sub __textarea { textarea(&_proc_value) }
sub __button { button($_[1]) }
sub __reset { reset($_[1]) }
sub __defaults { defaults($_[1]) }
sub __checkbox { checkbox(&_proc_defaults) }
sub __checkbox_group { checkbox_group(&_proc_defaults) }
sub __popup_menu { popup_menu(&_proc_defaults) }
sub __scrolling_list { scrolling_list(&_proc_defaults) }
sub __select { &__popup_menu }
sub __radio_group { radio_group(&_proc_default) }
sub __radio { &__radio_group }
sub __image_button { image_button($_[1]) }
sub __image { image_button($_[1]) }
sub __submit { submit($_[1]) }
package HTML::Template::Associate::FormField::Param;
use strict;
sub new {
my($class, $hash)= @_;
return bless $hash, $class;
}
sub param {
my($q, $key, $value)= @_;
return keys %$q if @_< 2;
$q->{$key}= $value if @_== 3;
$q->{$key};
}
package HTML::Template::Associate::FormField::Hidden;
use strict;
sub new {
my($class, $hidden)= @_;
$hidden= {} if (! $hidden || ref($hidden) ne 'HASH');
bless $hidden, $class;
}
sub set {
my($h, $key, $value)= @_;
if (@_== 3) {
if ($h->{$key}) {
if (ref($h->{$key}) eq 'ARRAY') {
push @{$h->{$key}}, $value;
} else {
$h->{$key}= [$h->{$key}, $value];
}
} else {
$h->{$key}= $value;
}
}
return();
}
sub unset {
my($h, $key)= @_;
delete $h->{$key} if @_== 2;
return();
}
sub get {
my($h, $key)= @_;
return _create_fields($h) if @_< 2;
return _create_field($key, $h->{$key});
}
sub exists {
my($h, $key)= @_;
if (@_== 2) {
if (ref($h->{$key}) eq 'ARRAY') {
return @{$h->{$key}} ? 1: 0;
} else {
lib/HTML/Template/Associate/FormField.pm view on Meta::CPAN
$tp->param('__PASSWD__', $form->param('Passwd'));
$tp->param('__SUBMIT__', $form->param('submit'));
print $cgi->header, $tp->output;
# If you move it as a plug-in of HTML::Template::Associate.
# * The code is an offer from "Alex Pavlovic" who is the author of HTML::Template::Associate.
use HTML::Template;
use HTML::Template::Associate;
my $associate = HTML::Template::Associate->new ({
target => 'FormField',
cgi => $cgi,
form_fields => \%formfields
});
my $template= HTML::Template->new (
scalarref=> \$example_template,
associate=> [ $associate ],
);
print $cgi->header, $template->output;
=head1 DESCRIPTION
This is Form Field object using bridge associate option of HTML::Template.
Fill in the Form Field which made from object follow the template.
If the Form Field data which was input at the previous screen exist, it is
easy to make code, because process (CGI pm dependense) of fill in Form is
automatic.
=head2 Form Field Setup
=over 4
=item *
The Form of the definition data of Form Field is HASH. And, contents of each
key is HASH, too.
=item *
The name of each key is hadled as name of Form Field. Also, in case of hadling
by B<HTML::Template, the name of key become enclosed with '__'> .
For example, Field that was defined Foo correspomds to B<__FOO__> of template.
=item *
The contents of each key certainly be defined the key ,type, which shows type
of Form Field.
=item *
The value of designate to type is same as method for making Form Field of
CGI.pm. B<Please refer to document of CGI.pm for details>.
B<startform> , B<start_multipart_form> , B<endform> , B<textfield> ,
B<filefield> , B<password_field> , B<textarea> , B<checkbox> , B<radio_group>
, B<popup_menu> , B<optgroup> , B<scrolling_list> , B<image_button> ,
B<defaults> , B<button> , B<reset>
=item *
And others, be possible to designate for extension Field type
at B<HTML::Template::Associate::FormField> are as follows:
B<form> ... other name of startform. I<(%)>
B<start_upload_form> ... other name of start_multipart_form. I<(%)>
B<upload_form> ... other name of start_multipart_form. I<(%)>
B<opt_form> ... return only a part of attribute of startform.
B<opt_multipart_form> ... return only a part of attribute of start_multipart_form.
B<opt_upload_form> ... other name of opt_multipart_form.
B<hidden_field> ... return all of no indication Field which is seting up.
B<hidden> ... other name of hidden_field
B<text> ... other name of textfield.
B<file> ... other name of filefield.
B<password> ... other name of password_field.
B<radio> ... other name of radio_group.
B<select> ... other name of popup_menu.
B<image> ... other name of image_button.
I<(%) In case of no indication Field was set up ,
connect the no indication Field and return the value.>
=item *
In case of you'd like to acquire the name from CGI query - it is different name
of the key which definition of Form Field, designate for the name of CGI query
as alias to contents of each key.
$cgi->param('Baz', 'Hello!!');
my %formfields= ( 'Foo'=> { alias=> 'Baz', type=> 'textfield' } );
=back
=head1 METHOD
=head2 new
Constructor
=over 4
=item 1
Accept CGI object or HASH reference to the first parameter.
=item 2
Accept definition of CGI Form (HASH reference) to the second parameter.
$form= HTML::Template::Associate::FormField-E<gt>B<new>($cgi, \%formfields);
=back
=head2 init
Constructor for HTML::Template::Associate.
=head2 param, params
Set up or refer to definition parameter of CGI Form.
=over 4
=item *
Get all keys which is defined as Form Field.
(B<All keys which was able to get by this are enclosed by '__'>)
$form-E<gt>B<param>;
=item *
Get the Form Field which was designated.
$form-E<gt>B<param>('Foo');
( run in 1.599 second using v1.01-cache-2.11-cpan-364913b4093 )