Posting to a form using Perl's LWP::Agent

I want to fill out a form on a web app using Perl and LWP::UserAgent.

If the form has multiple check boxes, and I only want to change one of them, do I have to post all of the fields to the form or can I just submit the one field that I want to change?

For example, in this form, all three items are presented as checked:  milk, butter, and cheese.  

<title>My Page</title>
<form name="myform" action="/myformhandler.cgi" method="POST">
<div align="left"><br>
<input type="checkbox" name="option1" value="Milk" checked> Milk<br>
<input type="checkbox" name="option2" value="Butter" checked> Butter<br>
<input type="checkbox" name="option3" value="Cheese" checked> Cheese<br>

<input type="submit" value=submit>

If I want to submit the form with cheese unchecked, can I do this?

use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla 8.0");
use HTTP::Request::Common qw(POST);
my $req = (POST '',
       [ option3 => 'off',
my $request = $ua->request($req);

Or do I have to submit all form items like this?

use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla 8.0");
use HTTP::Request::Common qw(POST);
my $req = (POST '',
       [ option1 => 'on',
         option2 => 'on',
         option3 => 'off'
my $request = $ua->request($req);

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hopkimiAuthor Commented:
I tested this against a form on a web server and proved for myself that I can construct requests that only send one out of the 20 name-value pairs to the form.  I don't have to resubmit every name-value pair to the form, just the ones I want to change.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.