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

Checkbox for boolean values

I am trying to use Tag::checkField to check one bool value in search, but if i dont click the box, it is not registered as 0 in search. If i click it, 1 is registered in search. Any suggestions? I tried few paramaters but i havend succeeded.

echo Tag::checkField(array("active", "value" => "1"));



5.2k
Accepted
answer
edited Jun '14

Hi,

Checkbox are sending in POST only when is checked. In Liftweb (Web Framework in Scala) I meet this solution for this:

echo Tag::hiddenField(array("active", "value" => "0"));
echo Tag::checkField(array("active", "value" => "1"));

This code produces hidden field with default value. The hidden field should be before checkbox. If your checkbox is checked the hidden value will be overridden.



17.0k

Good idea, i will try and let you know if it worked in all scenarios :)