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

\Phalcon\Tag - checked property problem

Hi, How do you handle checked option to <input type='checkbox' name='test' value='1' />

when i get value from database i tried to setup property checked by \Phalcon\Tag::setDefault to get <input type='checkbox' name='test' value='1' checked />

I did something like this RobotsController

   public function editAction()
   {
        $robots = Robots::findFirst("id = 'Android'");
        $this->view->setVar("robot_broken","data-not-checked");
        if($robots->broken == 1)
        {
            $this->view->setVar("robot_broken","checked");
        }
    }

in edit.phtml view i did

<div>Is robot broken?:
        <?php
        echo \Phalcon\Tag::checkField(array(
                "robot_broken",
                "value"=>1,
                $robot_broken => "checked"
            ))
        ?>
    </div>

This is my workaround If robot is broken then in checkbox is marked as checked="checked", when robot is not broken then checkbox is marked as data-not-checked="checked" :)

Maybe it help somebody, before it will be handle by framework. Maybe it could work in framework in this way, if not checked could be setup fake property data-fake-property='checked'



98.9k

This implementation is now fixed in 1.2.0