5
votes

According with the documentation

http://book.cakephp.org/3.0/en/views/helpers/form.html#options-for-select-checkbox-and-radio-inputs

I use "HiddenField" to create a hidden input with value 0.. Like this

 echo $this->Form->Label("Stats ");            
                echo $this->Form->checkbox('stats', [
                                'value' => '1',
                                'hiddenField' => '0',
                            ]);

My HTML (there is no hidden field) as it should:

<input type="checkbox" name="stats" value="1" required="required">

I did it yesterday, but today it's not working and i have not updated the cake version.. NOTHING, Crazy :\

2

2 Answers

3
votes

You did it wrong according to syntax .

Use following that I tested on localhost:

echo $this->Form->checkbox('stats',array(
                                'value' => '1',
                                'hiddenField' => true,
                            ));

Your issue : hiddenField' => '0', What you did is you set it to 0 , so in PHP it typecasts to false (datatype conversion in PHP) . So make it true.

My output :

<input type="hidden" name="data[CourseCategory][stats]" id="CourseCategoryStats_" value="0">
<input type="checkbox" name="data[CourseCategory][stats]" value="1" id="CourseCategoryStats">
-1
votes

Use for value =0 echo $this->Form->checkbox('done');