隐藏文本输入而不使其成为 `type="hidden"`

Hiding a text input without making it `type="hidden"`

我有什么

我在提交时使用 FormControllercreate 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

我试过的

请指教!

您可以创建隐藏输入并在需要时使其免于表单安全,方法是通过 unlockField() 方法解锁该字段:

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

或通过为 secure 选项传递 false'skip'

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

另见