CakePHP Hidden Input Field

So, I have this field that I want to keep in my form.

For this purpose I tried the following:

<?php echo $this->Form->input('group_id', array('hiddenField' => true, 'value'=> 2)); ?> 

I also tried:

 <?php echo $this->Form->input('group_id', array('options' => array('hiddenField'=> 'true'), 'value'=>2 )); ?> 

As I still see the input field.

What am I doing wrong?

+7
php cakephp
source share
3 answers

I suppose you are not reading the documentation correctly. hiddenField - enable / disable certain hidden fields for certain form fields.

You are either looking

 $this->Form->hidden('group_id') 

or

 $this->Form->input('group_id', ['type' => 'hidden']); 

I usually use only the latter.

See http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html

BUT, he said, you must not use any of them. And omit any fields that do not have a real purpose for the view and its shape. Instead, you should enter these fields in the data array before saving. See http://www.dereuromark.de/2010/06/23/working-with-forms/

+19
source share

If you want to add a hidden field that uses a linked second data array that will not be mailed or placed by default, you can use it to transfer:

 echo $this->Form->hidden('Group.name'); 

This is useful for re-editing page headers when a message or message encounters an error. A dynamic name can lose the Group.name data Group.name when your form is configured like this:

 <h1>Edit Group - <?php echo h($this->request->data['Group']['name']); ?></h1> 

For data to be stored in db, follow the directions above.

0
source share

Try entering code in cakephp 3 to set the hidden field

 <?php echo $this->Form->hidden('name'); ?> 
0
source share

All Articles