Yappo has asked for the wisdom of the Perl Monks concerning the following question:

I have a form with 3 fields named
headline thecontent categories[some_tag]
Script is as follows:
$mech->field("headline","MyHeadline"); $mech->field("thecontent","MyContent"); $mech->field("categories[some_tag]","Blah"); $mech->click("publish");

Problem: contents of headline and thecontent is submitted successfully, contents of categories[some_tag] is not.
I have tried all sorts of settings, but no success.
Do I have to replace some_tag???
Thanks.

Replies are listed 'Best First'.
Re: WWW::Mechanize:field not submitted
by ikegami (Patriarch) on Mar 11, 2009 at 03:58 UTC

    What makes you think categories[some_tag] is not being submitted? I'd love to see the value returned by

    $mech->response()->request()->as_string()

    Update: Works for me:

    use strict; use warnings; use URI::file qw( ); use WWW::Mechanize qw( ); my $mech = WWW::Mechanize->new(); $mech->get(URI::file->new_abs('file.html')); $mech->form_number(1); $mech->field("headline","MyHeadline"); $mech->field("thecontent","MyContent"); $mech->field("categories[some_tag]","Blah"); $mech->click("publish"); print $mech->response()->request()->as_string()
    <form method="POST"> <input type="text" name="headline" /> <input type="text" name="thecontent" /> <input type="text" name="categories[some_tag]" /> <input type="submit" name="publish" /> </form>
    POST file:///path/to/file.html Accept-Encoding: gzip Referer: file:///path/to/file.html User-Agent: WWW-Mechanize/1.34 Content-Length: 70 Content-Type: application/x-www-form-urlencoded headline=MyHeadline&thecontent=MyContent&categories%5Bsome_tag%5D=Blah
    >perl -wle"use LWP; print LWP->VERSION" 5.825 >perl -wle"use WWW::Mechanize; print WWW::Mechanize->VERSION" 1.34
      Thank you for your help.
      Problem was much simpler:
      within the form (60K) there was a hidden field; using this as field name instead worked...
      Thanks again for your efforts.
Re: WWW::Mechanize:field not submitted
by Gangabass (Vicar) on Mar 11, 2009 at 03:18 UTC
    What version of WWW::Mechanize did you use? Can you show your HTML code?
      Version is 1.34
      use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $mech->get("$mydomain/post.php"); $mech->form_number(2); $mech->field("headline","MyHeadline"); $mech->field("thecontent","MyContent"); $mech->field("categories[some_tag]","Blah"); $mech->click("publish");
        HTML code is too large. Line in question is:
        <input type="text" name="categories[some_tag]" class="categories form- +input-tip" size="16" value="Add Word" />
Re: WWW::Mechanize:field not submitted
by Anonymous Monk on Mar 11, 2009 at 03:12 UTC
    No, not if the fields name is categories[some_tag].
      It is. Any solution?
        Try using firefox w/Live HTTP Headers or Wireshark to see what gets sent by a live browser, then you can send the same thing using mechanize.