The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

problems with checkbox's Avatar

19 Jan, 2015 02:46 AM

I'm using slim (2.4.2, from composer install) with twig and try to send a post request with an array of checkboxes (see html code below). So only the LAST value is catched by $app->request->post(). I was analized the post request with firebug and is working ok, all the array was sended. Any ideas?

{% for man in mans %}
    <td><input type="checkbox" name="sel[]" value="{{man._id}}"></td>
{% endfor %}

PHP (controller)
$sel = $app->request()->post('sel[]');


FIREBUG (post request)
sel[] 54bc213647439fb808ed148d
sel[] 54bc21ad47439fb80834b04a
sel[] 54bc48ca47439fb8082473b4
sel[] 54bc49f747439fb808f12920

Thanks in advance.

  1. 1 Posted by Qiniso on 19 Jan, 2015 06:28 PM

    Qiniso's Avatar

    Try $sel = $app->request()->post('sel');

  2. 2 Posted by on 19 Jan, 2015 10:38 PM's Avatar

    I tried now, and return "null".
    Still with no ideas.....

  3. 3 Posted by Qiniso on 19 Jan, 2015 11:02 PM

    Qiniso's Avatar

    Can u check and ensure you have method="post" in your <form tag.

    If this doesn't help, then the problem might be something else...

  4. 4 Posted by on 20 Jan, 2015 06:39 PM's Avatar

    I wrote a response here early in this morning, but was not showed until now. 8-(((
    The line is:
    <form class="form-horizontal" action="ins" method="post">
    So, the post is there.

    I'm tried to pass a default value with sel (without brackets), that is 'ERROR!', and the result is 'ERROR!'. ;-)
    So, I think that nothing (with 'sel') is passed in this way.

    And I still need help. Any ideas?

  5. 5 Posted by on 03 Feb, 2015 09:53 PM's Avatar

    No one can help me with this? I've opened an issue in github, with identical treatment: no responses. So, I ask more one time: this is a bug, a missing feature or my code is wrong? If my code is wrong, please point WHERE. Follow gists from myfile.html.twig (template) and my route/controller myroute.php. (template) (controller/route)

  6. Support Staff 6 Posted by Andrew Smith on 14 Feb, 2015 11:05 AM

    Andrew Smith's Avatar

    This might be a server configuration issue, how about trying it with just pure PHP without Slim and see what the results are.

  7. 7 Posted by on 16 Feb, 2015 11:01 AM's Avatar

    Sorry about the very late reply. I have to manage this (yes, I do a workaround) to get things done.

    The code: // controller // view (twig template)

    With RAW PHP everything goes right, I do this test when I begin to ask. This is the
    "strangeness" of this issue.

  8. 8 Posted by Qiniso on 16 Feb, 2015 11:39 AM

    Qiniso's Avatar

    I see you're still using square brackets $sel = $app->request()->post('sel[]'); in your
    Pastie, line 7, and your Gist, line 6. This will not work whether you're using pure php, or any framework

    Have you tested both codes side-by-side? I'm curious as to what both code sets look, like, along with their respective results, and/or your "workaround"

  9. 9 Posted by on 16 Feb, 2015 06:30 PM's Avatar

    Yes, I use post('sel[]') with name="sel[]" and receive only ONE value. If I use post('sel') with name="sel[]" I receive NULL value. If I use post('sel') with name="sel" I receive ONLY one value. I can't understand what you mean, because the results are in the TOP of this thread ( with post('sel[]') ).
    My workaroud is in the links behind (using $app->request->params()), and I receive all of the variables that I need. // controller (is inside a group route) // twig html template (see that each "sel" is different. I mean that first is name="sel1", the second is name="sel2", and goes on.)

    Thanks for your soon reply. Here are Carnival holydays (in Brasil) and no one works until wednesday. ;-)
    But I'm alive and still read my messages.

  10. 10 Posted by on 16 Feb, 2015 06:47 PM's Avatar

    Sorry, that code isn't the code in this discussion. That code (in the last pastie) is what I'm working now. But the workaround will be the same. ;-)

    Best regards,

  11. 11 Posted by haard on 17 Aug, 2015 01:00 PM

    haard's Avatar

    Hi can you find the solution for that...

    Because I still gets only last value ...

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac