For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > June 2007 > setting a hidden field with WWW::Mechanize









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author setting a hidden field with WWW::Mechanize
Skywriter14

2007-06-23, 6:59 pm

Hello,

I have been trying to set some hidden form fields with WWW::Mechanize,
but I get error that they are read only.
Is it a cannot-be-done case for all hidden input form fields? Does
anyone has some tips for me?

These fields are some times hidden, sometimes visible textfields.
Right now I am going around like this:

my $mech = WWW::Mechanize->new();
my $self = bless {}, $class;
$self->{mech} = $mech;
..........
$self->{aaa} = 'some text';
# these fields sometimes are hidden, don't want to set them if they
are hidden, because that causes error
$self->{mech}->field( 'aaa' => $self->{aaa}, ) if ($self->{aaa}) && !
grep { m'aaa'i } @hidden_fields;
# list @hidden_fields is populated at runtime

But if there is a way to set these hidden fields that would be
helpful. Thanks.

--Sumon.

Tom Phoenix

2007-06-23, 6:59 pm

On 6/23/07, skywriter14 <sumonsmailbox@gmail.com> wrote:

> I have been trying to set some hidden form fields with
> WWW::Mechanize, but I get error that they are read only.


Have you seen this entry in the FAQ?

Why do I get "Input 'fieldname' is readonly"?

You're trying to change the value of a hidden field and you
have warnings on.

First, make sure that you actually mean to change the field
that you're changing, and that you don't have a typo. Usually,
hidden variables are set by the site you're working on for a
reason. If you change the value, you might be breaking some
functionality by faking it out.

If you really do want to change a hidden value, make the
changes in a scope that has warnings turned off:

{
local $^W = 0;
$agent->field( name => $value );
}

I found the FAQ here:

http://search.cpan.org/dist/WWW-Mec...chanize/FAQ.pod

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training
Skywriter14

2007-06-23, 6:59 pm

Hi Tom,

Thanks for your reply. (I am a big fan)

In fact I did read that FAQ. But missed the point actually. I made up
in my mind that warnings should be cured at all times, not ignored/
suppressed. But it makes sense turning off warning for that block.
And it solves my problem.

I was thinking of going for more complex solutions. Like deleting the
hidden fields and replacing them with textboxes with value, then
submitting the form. :-? But my head is healthy again.

--Sumon

On Jun 23, 11:49 pm, t...@stonehenge.com (Tom Phoenix) wrote:
> On 6/23/07, skywriter14 <sumonsmail...@gmail.com> wrote:
>
>
> Have you seen this entry in the FAQ?
>
> Why do I get "Input 'fieldname' is readonly"?
>
> You're trying to change the value of a hidden field and you
> have warnings on.
>
> First, make sure that you actually mean to change the field
> that you're changing, and that you don't have a typo. Usually,
> hidden variables are set by the site you're working on for a
> reason. If you change the value, you might be breaking some
> functionality by faking it out.
>
> If you really do want to change a hidden value, make the
> changes in a scope that has warnings turned off:
>
> {
> local $^W = 0;
> $agent->field( name => $value );
> }
>
> I found the FAQ here:
>
> http://search.cpan.org/dist/WWW-Mec...chanize/FAQ.pod
>
> Hope this helps!
>
> --Tom Phoenix
> Stonehenge Perl Training



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com