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

Hello! I would like to send values of my checked checkboxes from my first scrip to another script....and I'm not sure how to?

Here's my first script:
<form action="responsetest.cgi" method="post"> A<input type="checkbox" name="ch1" value="a"><br> B<input type="checkbox" name="ch1" value="b"><br> C<input type="checkbox" name="ch1" value="c"><br> D<input type="checkbox" name="ch1" value="d"><br> <input type="submit" value="send"> </form>
How can i put these(checked) values in an array or something and how
to send/recive that array in second script? Thanx a lot:)
Nejc

Replies are listed 'Best First'.
Re: sending values from checkboxes to another script
by Happy-the-monk (Canon) on Oct 11, 2004 at 12:29 UTC

    use CGI; # load CGI routines
    my $query = CGI->new; # create new CGI object
    my @ch1 = $query->param( 'ch1' ); # get contents of field ch1 as an array

    et voilà.

    Cheers, Sören

      It's simple and it works fine. Thanks a lot Sören:)
Re: sending values from checkboxes to another script
by mpolo (Chaplain) on Oct 11, 2004 at 12:45 UTC

    Happy-the-monk provided the correct answer here. I'm just going to add a bit of explanation, since your use of terminology may indicate a little bit of confusion.

    The code snippet that you cited would not normally be called a script. This is just an HTML page that calls a script. When someone visits your web page, his browser downloads that information and draws the page. When the user clicks on "submit", that information is sent back to your webserver and given to the program entitled "responsetest.cgi". As you have written the program, that program will need to be in the same directory as your web page. If your web server is running some version of Unix, that file must also be set as a "runnable file" (that is, the file permissions should be 755). On any web server, you will have to have the server set up to handle cgi scripts in any directory. If that's not the case and you don't know how to change it, you can usually put your script in the "cgi-bin" directory, and then access it as

    <form action="/cgi-bin/responsetest.cgi" method="post">

    The script responsetest.cgi will be written in perl (of course) and should use the CGI.pm module to avoid a lot of security problems. As Happy-the-monk showed, you will very easily be able to access the values put into your HTML form from within a CGI.pm-using perl script.

      I am much obliged to you for explanation.

      Nejc
Re: sending values from checkboxes to another script
by kutsu (Priest) on Oct 11, 2004 at 13:45 UTC

    Since sending input (via a form) is one of the first things you learn in CGI, I'd recommend you read Ovid's CGI Course, it should give you a basic intro. to CGI.

    "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce