Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Re: Re: a question about working with the forms and array

by arturo (Vicar)
on Oct 15, 2003 at 00:28 UTC ( #299296=note: print w/replies, xml ) Need Help??

in reply to Re: Re: a question about working with the forms and array
in thread a question about working with the forms and array

Really, seriously, use CGI instead of your hand-rolled procedure. It's been battle-tested, and is amazingly convenient to use; it handles all the URL-encoding and so forth, and deals with (inter alia) URLS that read like /, which would mess yours up. CGI will cut way down on the number of lines of code in your script, and make debugging easier. In fact, it's your hand-rolled procedure that appears to be the culprit. What you have in your HTML form, as generated by the script, is something like this:

<input type="checkbox" name="choice" value="foo.txt"> <input type="checkbox" name="choice" value="bar.txt">

And, assuming you check both boxes, there will be two name-value pairs in the input:
choice=foo.txt choice=bar.txt
and when your hand-rolled procedure runs, here's what happens: it encounters the first one, and sets $FORM{'choice'} to foo.txt; when it enounters the second one, it sets $FORM{'choice'} to bar.txt. So that's why you only see the last value.

Here's how you'd parse the form with CGI: at the top of your script, put use CGI qw(param); and to get the list of selected files, you'd simply add the one line @files = param('choice');. End of story.

I also want to lean hard on use strict. It may seem like it will make things more painful, but it will force you to think about which subroutines need access to which data. It will make your code so much more maintainable. And, as a final suggestion, I'd suggest you look into using CGI ;)

If not P, what? Q maybe?
"Sidney Morgenbesser"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://299296]
NodeReaper wonders through a maze of twisty little sayings, all alive

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2018-06-23 14:47 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.