Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cakephp hidden input field

Tags:

php

cakephp

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?

like image 996
Marc Rasmussen Avatar asked Oct 06 '13 19:10

Marc Rasmussen


People also ask

How do I add a hidden field in Cshtml?

The Html. Hidden() method generates a input hidden field element with specified name, value and html attributes.

How can I get form data in cakephp?

$data = $this->request->data; $someVariable = $data["name"]; Or, you can access any field directly, by using data() accessor: $someVariable = $this->request->data("name"); From this point, you can do anything you want with this variable.

What is FormHelper?

The FormHelper focuses on creating forms quickly, in a way that will streamline validation, re-population and layout. The FormHelper is also flexible - it will do almost everything for you using conventions, or you can use specific methods to get only what you need.


1 Answers

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', ['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/

like image 75
mark Avatar answered Oct 04 '22 07:10

mark