2

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.

dgw
  • 13,418
  • 11
  • 56
  • 54
jvector
  • 77
  • 1
  • 8

1 Answers1

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.

RET
  • 9,100
  • 1
  • 28
  • 33
  • Fantastic. Thank you so much. I knew it had to be something blindingly obvious! It's a long time since I messed with the innards of forms... "id is for CSS, name is for FORM processing" - I shall remember that mantra ;-) – jvector Feb 10 '12 at 09:04
  • You're welcome, glad to be able to help. It would probably be more accurate to say "id is for DOM manipulation, name is for FORM processing". By the way, you might like to consider ticking the answer - that's the SO system. cheers. – RET Feb 11 '12 at 06:40