}
elsif ($tag eq "select") {
# rename attributes reserved to come for the option tag
for ("value", "value_name") {
$attr->{"select_$_"} = delete $attr->{$_}
if exists $attr->{$_};
}
# count this new select option separately
$openselect{$attr->{name}}++;
while ($t = $p->get_tag) {
my $tag = shift @$t;
last if $tag eq "/select";
next if $tag =~ m,/?optgroup,;
next if $tag eq "/option";
if ($tag eq "option") {
my %a = %{$t->[0]};
# rename keys so they don't clash with %attr
for (keys %a) {
next if $_ eq "value";
$a{"option_$_"} = delete $a{$_};
}
while (my($k,$v) = each %$attr) {
$a{$k} = $v;
}
$a{value_name} = $p->get_trimmed_text;
$a{value} = delete $a{value_name}
unless defined $a{value};
$a{idx} = $openselect{$attr->{name}};
$f->push_input("option", \%a, $verbose);
}
else {
warn("Bad <select> tag '$tag' in $base_uri\n") if $verbose;
if ($tag eq "/form" ||
$tag eq "input" ||
$tag eq "textarea" ||
$tag eq "select" ||
$tag eq "keygen")
{
# MSIE implictly terminate the <select> here, so we
# try to do the same. Actually the MSIE behaviour
# appears really strange: <input> and <textarea>
# do implictly close, but not <select>, <keygen> or
# </form>.
my $type = ($tag =~ s,^/,,) ? "E" : "S";
$p->unget_token([$type, $tag, @$t]);
last;
}
}
}
}
elsif ($tag eq "keygen") {
$f->push_input("keygen", $attr, $verbose);
}
}
}
elsif ($form_tags{$tag}) {
warn("<$tag> outside <form> in $base_uri\n") if $verbose;
}
}
for (@forms) {
$_->fixup;
}
wantarray ? @forms : $forms[0];
}
sub new {
my $class = shift;
my $self = bless {}, $class;
$self->{method} = uc(shift || "GET");
$self->{action} = shift || Carp::croak("No action defined");
$self->{enctype} = lc(shift || "application/x-www-form-urlencoded");
$self->{inputs} = [@_];
$self;
}
sub push_input
{
my($self, $type, $attr, $verbose) = @_;
$type = lc $type;
my $class = $type2class{$type};
unless ($class) {
Carp::carp("Unknown input type '$type'") if $verbose;
$class = "TextInput";
}
$class = "HTML::Form::$class";
my @extra;
push(@extra, readonly => 1) if $type eq "hidden";
push(@extra, strict => 1) if $self->{strict};
delete $attr->{type}; # don't confuse the type argument
my $input = $class->new(type => $type, %$attr, @extra);
$input->add_to_form($self);
}
=item $method = $form->method
=3= |