Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
perl cgi无法打印php复选框数组中的元素_Php_Perl_Cgi - Fatal编程技术网

perl cgi无法打印php复选框数组中的元素

perl cgi无法打印php复选框数组中的元素,php,perl,cgi,Php,Perl,Cgi,我有一个HTML表单,它将复选框值作为数组发送到Perl CGI脚本。但是,由于该站点主要使用PHP重建,因此复选框数组的处理方式有所不同。我有一个返回表单的PHP函数。它看起来像这样: <td>Profiles: </td> <td><input type=\"checkbox\" value=\"oneconnect\" name=\"v1-profile[]\">OneConnect <br /> <input type=\

我有一个HTML表单,它将复选框值作为数组发送到Perl CGI脚本。但是,由于该站点主要使用PHP重建,因此复选框数组的处理方式有所不同。我有一个返回表单的PHP函数。它看起来像这样:

<td>Profiles: </td>
<td><input type=\"checkbox\" value=\"oneconnect\" name=\"v1-profile[]\">OneConnect <br />
<input type=\"checkbox\" value=\"http\" name=\"v1-profile[]\">HTTP <br />
<input type=\"checkbox\" value=\"xforwardedfor\" name=\"v1-profile[]\">Xforwarded-for</td>
</tr>
当我试图打印数组的元素时,我只看到单词数组作为输出

foreach my $r (@profiles1) {
print "$r\n";
}
我也试过一些不起作用的东西

foreach my $r (@profiles1) {
foreach my $v (@$r) {
print "$v\n";
}
}
如何访问@profiles1数组的元素?谢谢你的帮助

变量名后面的[]是一个PHP ism,它不是标准的,Perl的CGI模块或PHP以外的任何东西都不会专门处理它。如果可以,请将其从表单中删除。如果没有,您应该能够通过在名称中包含括号从Perl获取参数:

my @profiles = $q->param("v1-profile[]");

不确定你的问题是什么。这对我来说似乎很管用。这是我建造的小试验台

test.html:

<html>
  <head>
    <title>Test</title>
  </head>
  <body>
    <h1>Test</h1>
    <form action="/cgi-bin/form">
      <table>
        <tr>
          <td>Profiles: </td>
          <td><input type="checkbox" value="oneconnect" name="v1-profile[]">OneConnect <br />
          <input type="checkbox" value="http" name="v1-profile[]">HTTP <br />
          <input type="checkbox" value="xforwardedfor" name="v1-profile[]">Xforwarded-for<br />
          <input type="submit"></td>
        </tr>
      </table>
    </form>
  </body>
</html>
我完全明白我的期望。我选中的每个复选框都显示在输出中

foreach my $r (@profiles1) {
print "$r\n";
}
有一件事需要检查。提交表单后,您的URL是什么样子的?我的看起来像这样,选中了两个复选框

http://localhost/cgi-bin/form?v1-profile%5B%5D=oneconnect&v1-profile%5B%5D=xforwardedfor
请注意,输入名称中的方括号是URL编码的。这就是应该发生的事情


所以问题是,这与您的设置有何不同?

谢谢您的回答。当我从PHP表单中删除[]时,CGI脚本不会起作用。但是,如果选中多个复选框,我只看到1个元素发送到CGI脚本。我需要多个复选框。我还尝试按照您的建议将[]添加到参数名称中,但这不起作用。当时我甚至没有看到单词数组的输出。再次感谢您的建议。@dars33-这段代码和您的原始代码似乎都是在列表上下文中得到结果的,因此它应该会给出所有复选框的值。您是否看到类似于ARRAY0x27967ac的内容?这与数组不同,意味着您有一个只需要解引用的数组引用。
http://localhost/cgi-bin/form?v1-profile%5B%5D=oneconnect&v1-profile%5B%5D=xforwardedfor