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

Dear all

Im using HTTP::Request::Form to submit to a cgi link online.

Its going well, but I've come up against multiple checkboxes with the same name unfortunately:

<div class="database_category">Citation Databases:</div> <div class="edition"> <input type="checkbox" name="editions" checked value="D"> <a href="" onClick="return show_help( 'http://wos4.isiknowledge.com:80/LinkOut.cgi?dest=help/h_database.htm% +23sci&origin=http%3A//wos4.isiknowledge.com/CIW.cgi%3FSID%3DQVR5kArh@ +WcAAGvMDrs%26Func%3DGoBack');"> <img class="binfo" src="Images/info.gif" name="Information" alt="Information" title="Information" /> </a> Science Citation Index Expanded (SCI-EXPANDED)--1955-present </div> <div class="edition"> <input type="checkbox" name="editions" checked value="S"> <a href="" onClick="return show_help('http://wos4.isiknowledge.com: +80/LinkOut.cgi?dest=help/h_database.htm%23ssci&origin=http%3A//wos4.i +siknowledge.com/CIW.cgi%3FSID%3DQVR5kArh@WcAAGvMDrs%26Func%3DGoBack') +;"> <img class="binfo" src="Images/info.gif" name="Information" alt="Information" title="Information" /> </a> Social Sciences Citation Index (SSCI)--1956-present </div> <div class="edition"> <input type="checkbox" name="editions" checked value="H"> <a href="" onClick="return show_help('http://wos4.isiknowledge.com: +80/LinkOut.cgi?dest=help/h_database.htm%23ahci&origin=http%3A//wos4.i +siknowledge.com/CIW.cgi%3FSID%3DQVR5kArh@WcAAGvMDrs%26Func%3DGoBack') +;"> <img class="binfo" src="Images/info.gif" name="Information" alt="Information" title="Information" /> </a> Arts & Humanities Citation Index (A&HCI)--1975-present </div>
According to HTTP::Request::Form, the only value sent to the cgi link for 'editions' is the last one 'H' even if they were all checked. This is confirmed in a dump of the form:
FIELD{input/checkbox} editions=H FIELD{input/checkbox} editions=H FIELD{input/checkbox} editions=H
It was to my delight, that I realised that the checkboxes do have multiple values, much like radio buttons, but I can't access these different values via HTTP::Request::Form

So I want to fall back onto HTTP::Request::Common, which will enable me to submit any value to any field name, but my question is

What value should I send, if I wanted to indicate all the checkboxes were checked?
Should I just send 'DAH', and expect the cgi script to pasrse for all three values, or do I need a seperator?

Any help would be appreciated

Thanks
Sam

Updated Steve_p - Edited code so it wasn't all on one line

Replies are listed 'Best First'.
Re: Checkboxes with the same name
by ikegami (Patriarch) on Sep 24, 2004 at 23:12 UTC

    I looked at the source of HTTP::Request::Form verified that it is indeed a bug in the module. It uses $fieldvals{$name} = $value; to set the value, clobbering any existing value for that name.

    HTTP::Request::Common uses the query_form method of URI, whose documentation gives the following example:

    $uri->query_form(foo => 1, foo => 2); $uri->query_form(foo => [1, 2]); $uri->query_form([ foo => 1, foo => 2 ]); $uri->query_form([ foo => [1, 2] ]); $uri->query_form({ foo => [1, 2] });

    so:

    $ua->request(POST 'http://somewhere/foo', [ editions => [qw( D A H )], other_input => 'its value', ]);

    should do the trick

      ikegami

      Thanks for your reply, it was certainly what I was looking for

      However, I cant seem to get the right response. I used HTTP::Request::Form to print out the URL, with all the fields I knew I needed to fill, and used it as a guide.

      I've replaced all '&' with '\n' here for easier reading for the encoded URL string from HTTP::Request::Form:

      Func=Search Form=HomePage SID=QVgragrh%40WcAAB5MdZ8 topic=Enter+a+topic editions=H editions=H editions=H Period=Year+Range week_selection=LatestWeek years=2004 start_year=1955 end_year=2004 General+Search.x=2 General+Search.y=2
      And the code I'm using to try and replicate this, except for the editions, where Im following your example, is:
      $res = $ua->request(POST 'http://wos4.isiknowledge.com/CIW.cgi', [Func => 'Search', Form => 'HomePage', SID => $sid, topic => 'Enter+a+topic', editions => qw[(D A H)], Period => 'Year Range', week_selection => 'LatestWeek', years => 2004, start_year => 1955, end_year => 2004, 'General Search.x' => 2, 'General Search.y' => 2]);
      However, this is not producing the right response, and the HTTP::Request::Form method actually produced a better response, something is wrong with my attempt at using HTTP::Request::Common, but I dont know what it is that I'm doing wrong?

      Thanks for any help
      Sam </code>

        I'm confused as to why you're talking about HTTP::Request::Form again, since we established there was a bug in it.

        I ran a few tests:

        use URI; my $uri = URI->new("http://www.domain.com/"); $uri->query_form( editions => [qw( D A H )], ); print($uri->as_string(), "\n"); # http://www.domain.com/?editions=D&editions=A&editions=H

        so far so good

        use LWP; use HTTP::Request::Common; $request = POST 'http://www.domain.com/', [ editions => [qw( D A H )], ]; print($request->as_string(), "\n"); # POST http://www.domain.com/ # Content-Length: 54 # Content-Type: application/x-www-form-urlencoded # # editions=D&editions=A&editions=H

        Working great!

        >perl -MURI -le "print $URI::VERSION" 1.19 >perl -MLWP -le "print $LWP::VERSION" 5.64

        I'm not sure what you're trying to do. WWW::Mechanize might be of interest to you.