催化剂 $c->req->params 为空?

发布于 2025-01-03 19:42:16 字数 1249 浏览 0 评论 0原文

尝试用表单字段催化一些原型页面。我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月野兔 2025-01-10 19:42:16

你说得对。我怀疑您的 Catalyst 日志应该可以告诉您这里出了什么问题。问题不在于 Catalyst。

基本上,它是格式错误的 HTML - 每个表单输入都需要一个 name 参数,该参数可以在 POST 中传递回服务器。

      <select id="select02" name="select02">
        <option value="cat1">cat1</option>
        <option value="cat2">cat2</option>
      </select>

id 用于 CSS,name 用于 FORM 处理。

尝试一下,您应该会得到如下日志:

[11:31:28.499 16014:debug] Body Parameters are:

.-------------------+----------------------------------------.
| Parameter         | Value                                  |
+-------------------+----------------------------------------+
| select02          | cat1                                   |
| select06          | 2                                      |
'-------------------+----------------------------------------'

希望有帮助。

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.

      <select id="select02" name="select02">
        <option value="cat1">cat1</option>
        <option value="cat2">cat2</option>
      </select>

id is for CSS, name is for FORM processing.

Try that, and you should get logging like:

[11:31:28.499 16014:debug] Body Parameters are:

.-------------------+----------------------------------------.
| Parameter         | Value                                  |
+-------------------+----------------------------------------+
| select02          | cat1                                   |
| select06          | 2                                      |
'-------------------+----------------------------------------'

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文