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

Why checkbox return ON instead 1

Hi, I have a "active" field in my database and I have a search form with this field, like this:

<?php echo $this->tag->checkField(["active", "class" => "form-control", "id" => "fieldActivo"]) ?>

In my controller I get this with:

$this->request->getPost("active")

When I check this in my controller I recived ON instead 1 and I do not know why. My type field in database is TINYINT(1) and I tried with INT(1) with the same result.

Any idea?

Thx!



168
Accepted
answer

Try

<?php echo $this->tag->checkField(["active", "class" => "form-control", "id" => "fieldActivo", "value" => 1]) ?>



3.1k

Try

<?php echo $this->tag->checkField(["active", "class" => "form-control", "id" => "fieldActivo", "value" => 1]) ?>

And I suppose TAG component handle checkbox with ON....

FYI - the "on" value isn't just with Phalcon - it's just what browsers send when a checkbox is checked.