简体   繁体   English

如何处理Perl中的多选表单字段?

[英]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? 在Perl中,获取多选表单字段的选定值的最佳方法是什么?

<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'); 我得到这样的常规表单字段: $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. 如果你正在使用CGI模块(我真的希望你是),那么你可以通过将param hash分配给一个数组来访问多个值,CGI完成剩下的工作。 So in your example: 所以在你的例子中:

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

will store the selected values (2, 4) in the @mult array. 将所选值(2, 4)@mult数组中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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