X-Git-Url: http://git.shiar.nl/perl/html-form-simple.git/blobdiff_plain/90a3c98cbb649006619309f2d5f665453018bcdd..0e9c7322ba3c935e9d81f28e321297816af90f2f:/lib/HTML/Form/Simple.pm diff --git a/lib/HTML/Form/Simple.pm b/lib/HTML/Form/Simple.pm index 33da2b6..152efe9 100644 --- a/lib/HTML/Form/Simple.pm +++ b/lib/HTML/Form/Simple.pm @@ -171,7 +171,7 @@ sub select { sub radio { my $self = shift; - my ($name, $label, $rows, $attr) = $self->_attr(3, @_); + my ($name, $rows, $label, $default, $attr) = $self->_attr(4, @_); if (not defined $rows) { if (defined $label) { @@ -194,7 +194,7 @@ sub radio { } } - $self->select($name, $rows, {%$attr, type => 'radio'}); + $self->select($name, $rows, $default, {%$attr, type => 'radio'}); } sub check { @@ -202,7 +202,7 @@ sub check { my ($name, $label, $checked, $attr) = $self->_attr(3, @_); my $rows = defined $label ? ref $label eq 'ARRAY' ? [@$label] : [$label] : [{}]; - ref $_ eq 'HASH' or $_ = {label => $_} for @$rows; + $_ = ref $_ eq 'HASH' ? {%$_} : {label => $_} for @$rows; if (defined $checked) { if (ref $checked eq 'ARRAY') { $rows->[$_]->{checked} = $checked->[$_] for 0 .. $#$rows; @@ -213,6 +213,8 @@ sub check { } } exists $rows->[$_]->{value} or $rows->[$_]->{value} = $_ + 1 for 0 .. $#$rows; + $rows->[0]->{id} = $attr->{id} || $rows->[0]->{name} || $attr->{name} || $name #XXX: // + if ref $label ne 'ARRAY' and defined $rows->[0] and not defined $rows->[0]->{id}; $self->select($name, $rows, {%$attr, type => 'checkbox'}); } @@ -237,7 +239,7 @@ HTML::Form::Simple - Generate HTML form elements msg => 'Textarea default', {rows => 4, style => 'background:red'} ) ], [ Gender => join ' or ', $input->radio( - sex => ['m', 'f'] + sex => [qw(m f)], [qw(Male Female)] ) ], [ Colour => scalar $input->select( favcolour => [qw(Blue Green Red)], 'Green' @@ -248,15 +250,102 @@ HTML::Form::Simple - Generate HTML form elements ); say $input->stop; # -=head1 TODO +=head1 DESCRIPTION + +Set up a form object with new(). The HTML for the opening and closing +C<<
>> tags are returned by the start() and stop() methods. + +The L, L, L >> with specified name +and value (both are required by HTML specs). + + $input->hidden('name', 'value'); + +As with all methods, a final hash ref can be given to add further attributes. +While rarely needed in this case, it can also be used as an override or +alternative to value and name: + + $input->hidden({name => 'name', value => 'value'}) + +=item C + +The common C<< >>. + + $input->text('name', 'default'); + +If the I option is set, substitutes a similarly set up C<<