0
votes

What I have

I'm using the FormController to create inputs. A specific input will be frequently updated by Javascript for internal purposes and I want it hidden. In this case, I can't use type="hidden", instead it needs to be type="text" so that it won't be checked by the form tampering prevention when submitted.

What I tried

  • Adding 'hidden' => true to $this->Form->create() options works if the whole form needs to be hidden. That exact attribute doesn't seem to be working for individual inputs though, created using both $this->Form->input() and $this->Form->control()
  • For a specific input, first thing that comes to mind is adding 'style' => 'display:none' to its options, but that does not seem like a clean CakePHP-way solution
  • I think I've seen someone mention a way to do exactly that here. I think it was an attribute you'd add to the options. I searched around my answers and comments, using both this site and Google, but found nothing.

Please advise!

1
may i know what exactly you want to do?you are trying to hide the form or what - Soubhagya Kumar Barik

1 Answers

2
votes

You can create a hidden input and make it exempt from form security in case required, either by unlocking the field via the unlockField() method:

$this->Form->unlockField('field_name');
echo $this->Form->hidden('field_name');

or by passing false or 'skip' for the secure option:

echo $this->Form->hidden('field_name', ['secure' => false]);
echo $this->Form->hidden('field_name', [
    'secure' => \Cake\View\Helper\FormHelper::SECURE_SKIP
]);

See also