Jason Roth wrote:
I'm using www::mechanize to submit a form to a website, and one of the fields is disabled (and enabled by javascript on the page which obviously isn't running). When I try to set a value for this field I get a "no such field" error. How to I set a value for, and enable, disabled form fields?
Hi Jason WWW::Mechanize subclasses HTML::Form to handle the forms on a page. Ideally you would add an input to one of these objects, but they're designed to be created only from parsed HTML. The best way I can suggest is to create a new HTML::Form object from a scrap of HTML using the additional input field that the Javascript creates, find the HTML::Form::Input object in that and add it to the form on the original page. Fortunately an HTML::Form::Input object has an add_to_form method. Here's a little subroutine that does just that sub add_input { my $form = shift; my $html = shift; my $newform = HTML::Form->parse("<form>$html</form>", 'http://void'); my ($input) = $newform->inputs; $input->add_to_form($form); } and if you call it like the program below, hopefully you'll be able to add the input field that you need. It abuses the OO interface a little but it's the best I can come up with. HTH, Rob use strict; use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new; $mech->get('http://search.cpan.org'); my $form = $mech->form_number(1); add_input($form, '<input type="text" name="newfield">'); $mech->field(newfield => 42); $form->dump; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/