We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Array CheckField not being checked

Hi, i have a little problem, when i try for example:

{{ check_field("genre") }}

The checkbox works fine and is checked when form is submit, but if i try something like

{{ check_field("genre[10]") }}

It does not work

edited Nov '17

Looks like a bug with getValue:

It's looking for _POST[name] rather than taking into account arrays.

A possible workaround for this is:

    $_POST['genre[10]'] = $_POST['genre'][10];

If you need to do this on a global scale, this gets the job done:

        $repeat = false;
        foreach($_POST as $key => $value)
                foreach($value as $k=>$v)
                    if(!array_key_exists($key.'['.$k.']',$_POST))$repeat = true;
                    $_POST[$key.'['.$k.']'] = $v;

The while-loop is only necessary if you need support for mutlidimensional arrays like: genre[id][10]

This looks like an easy fix for cphalcon, we'll try to roll this out in the next release.