Mechanize and form->param()

Mechanize and form->param()

am 25.06.2007 19:48:13 von robbins.paul

------=_Part_5926_12561914.1182793693658
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

I'm unning into some trouble populating two option fields on a form
using Mechanize. They both have the same name
and when I try and use form->param("RequestMethods", "Direct",
"Print") it only sets the first one to Print and
doesn't set the second one. Any help is appreciated. The HTML code is below.

Thanks.

~Paul




Primary Delivery Method:






Backup Delivery
Method:





------=_Part_5926_12561914.1182793693658--

Re: Mechanize and form->param()

am 26.06.2007 05:41:03 von mumia.w.18.spam+nospam

On 06/25/2007 12:48 PM, Paul Robbins wrote:
> I'm unning into some trouble populating two option fields on a form
> using Mechanize. They both have the same name
> and when I try and use form->param("RequestMethods", "Direct",
> "Print") it only sets the first one to Print and
> doesn't set the second one. Any help is appreciated. The HTML code is
> below.
> [...]

Perhaps the POD for WWW::Mechanize can help:

> $mech->set_fields( $name => $value ... )
>
> This method sets multiple fields of the current form. It takes a list
> of field name and value pairs. If there is more than one field with the
> same name, the first one found is set. If you want to select which of
> the duplicate field to set, use a value which is an anonymous array
> which has the field value and its number as the 2 elements.

Re: Mechanize and form->param()

am 26.06.2007 15:44:13 von amalek

> On 6/26/07, Alex Malek wrote:
> > The problem is in HTML::Form.pm
> > I had the same issue and I wrote a fix for Form.pm
> > I am attaching it.
> >
> > Let me know if it helps.
> >
> > ---Alex
On 6/26/07, Paul Robbins wrote:
> What change did you make?
>
>

The problem is the way Form.pm deals with multiple form select options
with the same name.

I altered Form.pm to handle that case.

What you need to do is either replace Form.pm with the one I sent you
or put it in a place in your path where it is used first.

Below is the diff of the original Form.pm and and my new version.


153a155,156
> #select/option start code
> $attr->{START}="true";
156c159,164
< last if $tag eq "/select";
---
> if ($tag eq "/select") {
> #some select/option end code
> $attr->{END}="true";
> $f->push_input("option", $attr);
> last;
> }
172a181,183
> if ($attr->{START}) {
> delete $attr->{START}; #after first use remove
> }
188a200,202
> #some select/option end code
> $attr->{END}="true";
> $f->push_input("option", $attr);
823c837,851
< return $self->SUPER::add_to_form($form) unless $prev;
---
> # for option
> if ($type eq "option") {
> if ( defined $self->{START}) {
> return $self->SUPER::add_to_form($form);
> }
> my $i=1;
> while ($prev && (! defined $prev->{START}) ) {
> $prev = $form->find_input($self->{name}, $self->{type}, $i++);
> }
> if ( defined $prev->{START} && defined $self->{END}) {
> delete $prev->{START};
> return;
> }
> }
> return $self->SUPER::add_to_form($form) unless ($prev );

Re: Mechanize and form->param()

am 26.06.2007 15:52:32 von robbins.paul

------=_Part_19604_20828077.1182865952198
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Alex,
You are a lifesaver!! Have you talked to the people that host Form.pm to
have this change implemented?

~Paul

On 6/26/07, Alex Malek wrote:
>
> > On 6/26/07, Alex Malek wrote:
> > > The problem is in HTML::Form.pm
> > > I had the same issue and I wrote a fix for Form.pm
> > > I am attaching it.
> > >
> > > Let me know if it helps.
> > >
> > > ---Alex
> On 6/26/07, Paul Robbins wrote:
> > What change did you make?
> >
> >
>
> The problem is the way Form.pm deals with multiple form select options
> with the same name.
>
> I altered Form.pm to handle that case.
>
> What you need to do is either replace Form.pm with the one I sent you
> or put it in a place in your path where it is used first.
>
> Below is the diff of the original Form.pm and and my new version.
>
>
> 153a155,156
> > #select/option start code
> > $attr->{START}="true";
> 156c159,164
> < last if $tag eq "/select";
> ---
> > if ($tag eq "/select") {
> > #some select/option end code
> > $attr->{END}="true";
> > $f->push_input("option", $attr);
> > last;
> > }
> 172a181,183
> > if ($attr->{START}) {
> > delete $attr->{START}; #after first use remove
> > }
> 188a200,202
> > #some select/option end code
> > $attr->{END}="true";
> > $f->push_input("option", $attr);
> 823c837,851
> < return $self->SUPER::add_to_form($form) unless $prev;
> ---
> > # for option
> > if ($type eq "option") {
> > if ( defined $self->{START}) {
> > return $self->SUPER::add_to_form($form);
> > }
> > my $i=1;
> > while ($prev && (! defined $prev->{START}) ) {
> > $prev = $form->find_input($self->{name}, $self->{type}, $i++);
> > }
> > if ( defined $prev->{START} && defined $self->{END}) {
> > delete $prev->{START};
> > return;
> > }
> > }
> > return $self->SUPER::add_to_form($form) unless ($prev );
>

------=_Part_19604_20828077.1182865952198--