Search code examples
cakephpinputcheckboxformhelper

How can input change between normal text type and checkbox in cakephp?


In one of my friend's cakephp project,her colleague wrote a checkbox like this :

https://pbs.twimg.com/media/BKt5D1lCAAA1ZfJ.jpg

And he created it in this way:

echo $this->Form->input('accept_twins', array('label' => 'Accept twins?'));

How could it be!?!!!

If I change anything in the fieldname param 'accept_twins',or copy it to other ctp file,it comes to this:

https://pbs.twimg.com/media/BKuAunRCEAAVAWs.jpg

How could it !!!!!!!!!!!!!!!Whether there are such rules?

Actually,I know how to create a nomarl checkbox,I just can't understand how could this happen?Does anyone know it?

妈蛋!累感不爱!蠢哭了!


Solution

  • The formhelper guesses the input type to use based on db field type. If it shows checkbox it means the field accept_twins is of type TINYINT(1) in the table for that particular model. If you change the field name it will change the input type based on type of that field in db or show input type text by default if the field isn't in db.