催化剂 $c->req->params 为空?
尝试用表单字段催化一些原型页面。我的 Catalyst 控制器在提交表单时似乎没有从表单获取输入。
我试图减少模板和控制器已尽我所能,但我仍然遇到这个问题。
模板很简单:
<body>
<form action="/minimal-testing" method="get">
<select id="select02">
<option value="cat1">cat1</option>
<option value="cat2">cat2</option>
</select>
<select id="select06">
<option value="1">1</option>
<option value="2">2</option>
</select>
<input type="submit" value="submit" title="submit" />
</form>
<p> Hello, params says: </p>
<p>
[% FOR param IN params ; param.key ; ' = ' ; param.value; END %]
</p>
</body>
控制器是:
sub minimal_testing :Path('minimal-testing') :Args(0) {
use Data::Dumper;
my ( $self, $c ) = @_;
$c->stash(params=>$c->req->params);
$c->stash(template => "dynamic/minimal-testing.tt");
$c->log->debug(Dumper($c->request->params));
}
当我浏览到表单,从选择选项中进行选择并提交时,我的调试日志只是说
[debug] $VAR1 = {};
显然我错过了一些东西,所以显然我只是没有看到它......请赐教。
Trying to Catalyse some prototype pages with form fields. My Catalyst controller does not seem to be getting the inputs from the form when it is submitted.
I have tried to reduce the template & controller down as far as I can and I am still getting this problem.
template is simply:
<body>
<form action="/minimal-testing" method="get">
<select id="select02">
<option value="cat1">cat1</option>
<option value="cat2">cat2</option>
</select>
<select id="select06">
<option value="1">1</option>
<option value="2">2</option>
</select>
<input type="submit" value="submit" title="submit" />
</form>
<p> Hello, params says: </p>
<p>
[% FOR param IN params ; param.key ; ' = ' ; param.value; END %]
</p>
</body>
Controller is:
sub minimal_testing :Path('minimal-testing') :Args(0) {
use Data::Dumper;
my ( $self, $c ) = @_;
$c->stash(params=>$c->req->params);
$c->stash(template => "dynamic/minimal-testing.tt");
$c->log->debug(Dumper($c->request->params));
}
When I browse to the form, pick from the select options, and submit, my debug log simply says
[debug] $VAR1 = {};
Obviously I am missing something so obvious I am just not seeing it... please enlighten me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你说得对。我怀疑您的 Catalyst 日志应该可以告诉您这里出了什么问题。问题不在于 Catalyst。
基本上,它是格式错误的 HTML - 每个表单输入都需要一个
name
参数,该参数可以在 POST 中传递回服务器。id
用于 CSS,name
用于 FORM 处理。尝试一下,您应该会得到如下日志:
希望有帮助。
You're dead right. I suspect your Catalyst log should be giving you a clue what's going wrong here. The problem isn't with Catalyst.
Basically, it's malformed HTML - your form inputs each need a
name
parameter that can be passed back to the server in the POST.id
is for CSS,name
is for FORM processing.Try that, and you should get logging like:
Hope that helps.