Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP 3 - Creating hiddenField

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 :\

like image 554
TMoraes Avatar asked Nov 01 '22 10:11

TMoraes


1 Answers

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">
like image 140
Pratik Avatar answered Nov 09 '22 00:11

Pratik