Marc Rasmussen Marc Rasmussen - 6 months ago 37
PHP Question

Cakephp hidden input field

So i have this field i want to keep hidden in my form.

For this purpose i have 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 )); ?>


How ever i still see the input field..

What am i doing wrong?

Answer

You misread the documentation, I assume. hiddenField is to enable/disable specific hidden fields for specific form fields.

You are either looking for

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

or

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

I usually only use the latter.

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

BUT - that said - you shouldnt actually use either one of those. And omit any fields that serve no real purpose for the view and its form. Instead you should inject those fields into the data array prior to saving. See http://www.dereuromark.de/2010/06/23/working-with-forms/