Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cakephp hidden field issue

I have a problem with an input field in a view called add.ctp. When the input type is set to 'text', the program sequence is normal. But when I change the input type to 'hidden', the following error is displayed:

The request has ben black-holed. Error: The requested address was not found on this server.

mod-rewrite seems activated. Any ideas, what can be the reason for this?

like image 432
user2610983 Avatar asked Oct 21 '25 20:10

user2610983


2 Answers

There is no error with your code. CakePHP's Security component checks hidden form fields to prevent tampering by end users:

By default SecurityComponent prevents users from tampering with forms. It does this by working with FormHelper and tracking which files are in a form. It also keeps track of the values of hidden input elements. All of this data is combined and turned into a hash. When a form is submitted, SecurityComponent will use the POST data to build the same structure and compare the hash.

Use FormHelper::unlockField to make a field exempt from this feature:

$this->Form->unlockField('User.id');
like image 73
Jacob Budin Avatar answered Oct 25 '25 12:10

Jacob Budin


This means there is an error with your code. Here is how to create hidden textbox

   echo $this->Form->input('field_name', array('type'=>'hidden'));
like image 45
Fury Avatar answered Oct 25 '25 13:10

Fury