develooper Front page | perl.libwww | Postings from March 2003

trouble with <SELECT> inputs in HTML::Form

Thread Next
From:
Ask Bjoern Hansen
Date:
March 25, 2003 20:44
Subject:
trouble with <SELECT> inputs in HTML::Form
Message ID:
86isu691pp.fsf@miette.develooper.com

I can't get <SELECT>'s to work.  Specifically then input->{menu} isn't
being populated properly, I think.  The dump is okay, but
->possible_values doesn't return all the possible values and ->value
gives me an error if I use anything but the first option.

First I thought it had to do with missing new lines, but that appears
not to be the case.

Output (test script follows): 

$ perl form.pl 
GET http://example.com/
  newlines=<UNDEF>                (option)  [*<UNDEF>|x1]
  newlines=<UNDEF>                (option)  [*<UNDEF>|x2]
  newlines=<UNDEF>                (option)  [*<UNDEF>|x3]
  nonewlines=<UNDEF>              (option)  [*<UNDEF>|x1]
  nonewlines=<UNDEF>              (option)  [*<UNDEF>|x2]
  nonewlines=<UNDEF>              (option)  [*<UNDEF>|x3]
Use of uninitialized value in join or string at form.pl line 12, <DATA> chunk 1.
newlines:  / x1
Illegal value 'x3' at form.pl line 13
Use of uninitialized value in join or string at form.pl line 12, <DATA> chunk 1.
nonewlines:  / x1
Illegal value 'x3' at form.pl line 13


I obviously expected possible_values to have x1..x2 and the value call
to not croak.


 - ask


#!/usr/bin/perl -w
use strict;
use HTML::Form;

$/ = undef;

my $form = HTML::Form->parse(<DATA>, 'http://example.com/');
print $form->dump;

for my $f (qw(newlines nonewlines)) {
  my $input = $form->find_input($f);
  print "$f: ", join(" / ", $input->possible_values), "\n";
  eval { $form->value($f => "x3") };
  warn $@ if $@;
}


__DATA__
<form action="/">

<SELECT NAME="newlines" MULTIPLE>
<OPTION VALUE="x1">x1
<OPTION VALUE="x2">x2
<OPTION VALUE="x3">x3
</SELECT>

<SELECT NAME="nonewlines" MULTIPLE>
<OPTION VALUE="x1">x1<OPTION VALUE="x2">x2<OPTION VALUE="x3">x3
</SELECT>

</form>


-- 
ask bjoern hansen, http://www.askbjoernhansen.com/ !try; do();

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About