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:
https://github.com/phalcon/cphalcon/blob/master/phalcon/tag.zep#L331

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:

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

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.