简体   繁体   中英

How do I handle a multiple select form field in Perl?

What is the best, in Perl, way to get the selected values of a multiple select form field?

<select name="mult" multiple="multiple">
   <option value="1">Opt. 1</option>
   <option value="2">Opt. 2</option> <!-- selected -->
   <option value="3">Opt. 3</option> 
   <option value="4">Opt. 4</option> <!-- selected -->
   <option value="5">Opt. 5</option>
</select>

I get regular form fields like this: $param1 = param('param1');

If you are using the CGI Module (and I really hope you are) then you can access the multiple values by assigning the param hash to an array and CGI does the rest. So in your example:

my @mult = $q->param('mult');

will store the selected values (2, 4) in the @mult array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM