Allen Allen - 11 days ago 6
HTML Question

Perl ReadParse to process SELECT html tag with multiple options slected

How do I access all the options selected from a SELECT tag which is then passed into a form using POST
The HTML form is setup like this:

<div class="header">
<FORM ACTION=/cgi-local/process.pl METHOD=POST>
<p>
CMS:
</p>
<h6>Hold Down control(CTRL) key to select multiple CMSs</h6>

<SELECT NAME = "cms" multiple>

<option></option>>
<option>#1 - 15 N 0.4 N/O ONTARIO AVE</option>>
<option>#2 - 15 S 1.1 S/O 6TH</option>>
<option>#3 - 215 N CENTRAL 215</option>>
<option>#4 - 215 S 0.45 S/O IOWA</option>>

</SELECT>
</p>
<INPUT TYPE=SUBMIT VALUE="Submit Form" align="center">

</FORM>
</INPUT>
</div>


The Perl portion where it handles the POST data using ReadParse:

use CGI qw(:cgi-lib :standard);
&ReadParse(%in);

$cms = $in{"cms"};


Displaying the content of
$cms
just shows the first option selected despite multiple selection. How do I access the passed in data?

Answer
use CGI qw(:cgi-lib :standard);
&ReadParse(%in);

Aaaah, the nineties...

How do I access all the options selected from a SELECT tag?

Use multi_param:

my @v = multi_param('cms');

In doing so, you'll be giving up compatibility with Perl 4's cgi-lib.pl. That is, don't use &ReadParse(%in); Instead, access values of CGI parameters using param and ditch the %in hash.

According to perldoc perlhist, last version of Perl 4 was released in 1993:

Larry 4.036 1993-Feb-05 Very stable.

You may be stuck with an older version of CGI.pm. It was added in 2014. If that is the case, you can use my @v = param('cms'); but do read the documentation.

Comments