Disabling input elements in a CakePHP form that uses Security component and jQuery

…衆ロ難τιáo~ 提交于 2019-12-04 13:46:00

It happens because the Security Component locks the hidden fields, saving in the hash not just their name but also their value. Therefore when you change their value, you make the whole form invalid. The only solution is to switch those fields from hidden to normal field, wrapped inside a display:none; div.

Another way would be to disable the checks on that field, but the code you posted isn't the right way to do it. You should instead specify the fields during the configuration of the component, like this:

var $components = array('Security' => array(
    'blackHoleCallback' => 'callback',
    'requireAuth' => array('action1', 'action2'),
    'allowedControllers' => array('controller'),
    'allowedActions' => array('action1', 'action2'),
    'disabledFields' => array('Record.program_id_search', 'Record.concept_id_search')
    )
);

An easier way to have solved this that I just discovered would have been to add 'secure' => false to your input's attribute array. This prevents them from being added to the secure fields list.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!