Problem with <SELECT MULTIPLE> in Mech (maybe in HTTP::Form as well?)
am 14.07.2005 18:46:01 von HalI'm having problems with a
I'm having problems with a
$option->{'menu'}[1]{'value'} is the value of the option
I got all of the options and walked thru the list till the value
matched the one I wanted and then using $option->check worked for me -
where $option is the option to be selected.
I "found" the check method in the code for HTML::Form
On Jul 14, 2005, at 12:46 PM, Hal Vaughan wrote:
> I'm having problems with a
> this seems
> like it is not just Mech, but a problem with HTTP::Form as well. In
> short,
> this item is a
> value, I got error messages, so I changed my code to retreive the
> object and
> print out the possible values and the value names. It did not print
> out the
> values available in the code, so I changed my code to retreive an
> array of
> objects and found that this one
> treated as
> a number of OPTION objects. The HTML was not complete (the
> tags
> were missing), so I got the page, fixed it with a few regexes, then
> replaced
> the HTML, and that didn't fix the problem. After experimenting, I
> found that
> once I removed the MULTIPLE keyword from the
> was then
> seen as one object, and I could use it as expected. I need to know if
> I'm
> doing something wrong, or why a
>
> can
> select ONE value in a
> more
> below.
>
> Here's the code for the form object I'm dealing with (the form itself
> is okay,
> it seems to be this and a few other
> the
> problem:
>
>
>
>
>
>
>
>
>
> When I cleaned it up, it was like this:
>
>
>
>
>
>
>
>
>
> This did not make a difference. The only thing that did make a
> difference was
> when I removed "MULTIPLE". I changed my code to set the
> value to
> get the OPTION object(s), step through each one, and list the possible
> values
> and value names. Here's the subroutine I used:
>
>
> sub setselectname {
> my ($form, $option, $name, $val, @obj, @val);
> ($name, $val) = @_;
> if (!checkformelement($name, "option")) {return 0;}
> $form = $mech->current_form();
> @opt = $form->find_input($name, "option");
> print "--------------------------------------------------------\n" ;
> print "Option name: $name, Count found: $#opt\n";
> foreach (@opt) {
> print "Option:\n";
> @val = $_->possible_values();
> foreach (@val) {
> print "\tValue: $_\n";
> }
> @val = $_->value_names();
> foreach (@val) {
> print "\tName: $_\n";
> }
> }
> return 1;
> }
>
> Originally, to set the
>
> $mech->select($name, $val);
>
> And once I realized the problem was with the MULTIPLE keyword, I tried:
>
> $mech->select($name, \@val)
>
> Just in case it needed an array (only the first array element was set).
>
> And here's the code it outputs if the MULTIPLE keyword is left in:
>
> --------------------------------------------------------
> Option name: locatoin, Count found: 4
> Option:
> Value:
> Value:
> Name: off
> Name:
> Option:
> Value:
> Value: 1
> Name: off
> Name: East End
> Option:
> Value:
> Value: 2
> Name: off
> Name: West End
> Option:
> Value:
> Value: 3
> Name: off
> Name: Southside
> Option:
> Value:
> Value: 4
> Name: off
> Name: Northside
>
>
> And here's the code it outputs if the MULTIPLE keyword is left out:
>
> --------------------------------------------------------
> Option name: location Count found: 0
> Option:
> Value:
> Value: 1
> Value: 2
> Value: 3
> Value: 4
> Name:
> Name: East End
> Name: West End
> Name: Southside
> Name: Northside
>
> So if the MULTIPLE keyword is in, it sees each
> item. I
> can understand that, but there is no way for me to access the entire
>
> of the
>
> wrong?
>
> I'm under a deadline and everything was going great (I even thought I'd
> actually get a weekend off!) until this came up. I need to resolve
> it, so
> any help is greatly appreciated!
>
> Thanks!
>
> Hal
>
On Thursday 14 July 2005 04:26 pm, Warren Pollans wrote:
> $option->{'menu'}[1]{'value'} is the value of the option
>
> I got all of the options and walked thru the list till the value
> matched the one I wanted and then using $option->check worked for me -
> where $option is the option to be selected.
>
> I "found" the check method in the code for HTML::Form
That gives me the options and lets me read them as one unit.
Have you then submitted the page and seen if the server responded to it?
(I'll be trying that soon, but once I submit, I get a report that costs money,
so I want to make sure everything is right and I'm not sending through a
bunch of trial runs unless I'm pretty sure they'll work.)
Does anyone have examples of
HTML code) that don't have this problem, or is it a bug that nobody's
realized yet because there aren't many cases of people needing to use
multiple selects? (Or is it a "feature" that I just don't fully appreciate?)
Thanks!
Hal
> On Jul 14, 2005, at 12:46 PM, Hal Vaughan wrote:
> > I'm having problems with a
> > this seems
> > like it is not just Mech, but a problem with HTTP::Form as well. In
> > short,
> > this item is a
> > value, I got error messages, so I changed my code to retreive the
> > object and
> > print out the possible values and the value names. It did not print
> > out the
> > values available in the code, so I changed my code to retreive an
> > array of
> > objects and found that this one
> > treated as
> > a number of OPTION objects. The HTML was not complete (the
> > tags
> > were missing), so I got the page, fixed it with a few regexes, then
> > replaced
> > the HTML, and that didn't fix the problem. After experimenting, I
> > found that
> > once I removed the MULTIPLE keyword from the
> > was then
> > seen as one object, and I could use it as expected. I need to know if
> > I'm
> > doing something wrong, or why a
> >
> > can
> > select ONE value in a
> > more
> > below.
> >
> > Here's the code for the form object I'm dealing with (the form itself
> > is okay,
> > it seems to be this and a few other
> > the
> > problem:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > When I cleaned it up, it was like this:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > This did not make a difference. The only thing that did make a
> > difference was
> > when I removed "MULTIPLE". I changed my code to set the
> > value to
> > get the OPTION object(s), step through each one, and list the possible
> > values
> > and value names. Here's the subroutine I used:
> >
> >
> > sub setselectname {
> > my ($form, $option, $name, $val, @obj, @val);
> > ($name, $val) = @_;
> > if (!checkformelement($name, "option")) {return 0;}
> > $form = $mech->current_form();
> > @opt = $form->find_input($name, "option");
> > print "--------------------------------------------------------\n" ;
> > print "Option name: $name, Count found: $#opt\n";
> > foreach (@opt) {
> > print "Option:\n";
> > @val = $_->possible_values();
> > foreach (@val) {
> > print "\tValue: $_\n";
> > }
> > @val = $_->value_names();
> > foreach (@val) {
> > print "\tName: $_\n";
> > }
> > }
> > return 1;
> > }
> >
> > Originally, to set the
> >
> > $mech->select($name, $val);
> >
> > And once I realized the problem was with the MULTIPLE keyword, I tried:
> >
> > $mech->select($name, \@val)
> >
> > Just in case it needed an array (only the first array element was set).
> >
> > And here's the code it outputs if the MULTIPLE keyword is left in:
> >
> > --------------------------------------------------------
> > Option name: locatoin, Count found: 4
> > Option:
> > Value:
> > Value:
> > Name: off
> > Name:
> > Option:
> > Value:
> > Value: 1
> > Name: off
> > Name: East End
> > Option:
> > Value:
> > Value: 2
> > Name: off
> > Name: West End
> > Option:
> > Value:
> > Value: 3
> > Name: off
> > Name: Southside
> > Option:
> > Value:
> > Value: 4
> > Name: off
> > Name: Northside
> >
> >
> > And here's the code it outputs if the MULTIPLE keyword is left out:
> >
> > --------------------------------------------------------
> > Option name: location Count found: 0
> > Option:
> > Value:
> > Value: 1
> > Value: 2
> > Value: 3
> > Value: 4
> > Name:
> > Name: East End
> > Name: West End
> > Name: Southside
> > Name: Northside
> >
> > So if the MULTIPLE keyword is in, it sees each
> > item. I
> > can understand that, but there is no way for me to access the entire
> >
> > of the
> >
> > wrong?
> >
> > I'm under a deadline and everything was going great (I even thought I'd
> > actually get a weekend off!) until this came up. I need to resolve
> > it, so
> > any help is greatly appreciated!
> >
> > Thanks!
> >
> > Hal
On Thu, Jul 14, 2005 at 05:01:40PM -0400, Hal Vaughan (hal@thresholddigital.com) wrote:
> Does anyone have examples of
> HTML code) that don't have this problem, or is it a bug that nobody's
> realized yet because there aren't many cases of people needing to use
> multiple selects? (Or is it a "feature" that I just don't fully appreciate?)
I THINK it's an issue down at the HTML::Form level.
--
Andy Lester => andy@petdance.com => www.petdance.com => AIM:petdance
On Thursday 14 July 2005 05:04 pm, Andy Lester wrote:
> On Thu, Jul 14, 2005 at 05:01:40PM -0400, Hal Vaughan
(hal@thresholddigital.com) wrote:
> > Does anyone have examples of
> > sample HTML code) that don't have this problem, or is it a bug that
> > nobody's realized yet because there aren't many cases of people needing
> > to use multiple selects? (Or is it a "feature" that I just don't fully
> > appreciate?)
>
> I THINK it's an issue down at the HTML::Form level.
I figured it was more at the form level, since the problem persisted with the
Option object, which was from the Form object. After reading your post, I
re-read the HTTP::Form doc on CPAN. I missed this the first time around, but
I did find this:
"For a
object of type of "option". For a
input object for each contained
objects will have the same name."
So I figure this isn't a bug, but is the way this is handled. It's damned
frustrating. It means you have to handle setting values for a
The part I find frustrating is that I won't know how well this works until I
submit the form to the site I'm dealing with, and that means I pay for a
report. Is there some way to find out, before calling $form->submit() what
will be POSTed when the form/page is submitted?
Hal
On Thu, 14 Jul 2005, Hal Vaughan wrote:
The part I find frustrating is that I won't know how well this works until I
submit the form to the site I'm dealing with, and that means I pay for a
report. Is there some way to find out, before calling $form->submit() what
will be POSTed when the form/page is submitted?
isnt there an as_string method on the request object?
mfp
Hal
--
gedanken
On Thu, Jul 14, 2005 at 05:16:53PM -0400, Hal Vaughan (hal@thresholddigital.com) wrote:
> The part I find frustrating is that I won't know how well this works until I
> submit the form to the site I'm dealing with, and that means I pay for a
> report. Is there some way to find out, before calling $form->submit() what
> will be POSTed when the form/page is submitted?
Sure. Make your own HTTP::Request object. Do the dirty work that Mech
does for you.
xoxo,
Andy
--
Andy Lester => andy@petdance.com => www.petdance.com => AIM:petdance
On Thursday 14 July 2005 05:30 pm, Gedanken wrote:
> On Thu, 14 Jul 2005, Hal Vaughan wrote:
>
> The part I find frustrating is that I won't know how well this works until
> I submit the form to the site I'm dealing with, and that means I pay for a
> report. Is there some way to find out, before calling $form->submit() what
> will be POSTed when the form/page is submitted?
>
> isnt there an as_string method on the request object?
I have to plead ignorance here -- I can't even see how I can get a request
object from Mech before it is sent (or even at all).
Hal
On Thursday 14 July 2005 05:46 pm, Andy Lester wrote:
> On Thu, Jul 14, 2005 at 05:16:53PM -0400, Hal Vaughan=20
(hal@thresholddigital.com) wrote:
> > The part I find frustrating is that I won't know how well this works
> > until I submit the form to the site I'm dealing with, and that means I
> > pay for a report. Is there some way to find out, before calling
> > $form->submit() what will be POSTed when the form/page is submitted?
>
> Sure. Make your own HTTP::Request object. Do the dirty work that Mech
> does for you.
>
> xoxo,
> Andy
I'd rather not. =A0In this case, since there doesn't seem to be a way to se=
t a=20
=20
read the object and see if it has been changed, and so far I can't verify i=
t. =A0
That's why I want to find some way to verify just what is being sent out.
I've tried (after setting the correct form)
$mech->select($name, $val)
and
$mech->select($name, \@val)
with a 1 element array, and neither is working. =A0I realize that HTTP::For=
m=20
handles multiple selects differently, but it seems impossible to set a=20
what=20
I'm doing with the above methods and that there is an answer that I, in my=
=20
exhausted state, am missing. =A0The first method above works perfectly -- a=
s=20
long as the
Hal