cakephp checkbox is showing extra hidden field

你说的曾经没有我的故事 提交于 2020-01-03 20:01:19

问题


foreach($apps as $app){


        echo $this->Form->input('Application', array('type'=>'checkbox', 'id'=>$app['Application']['description'], 'div'=>false,'type'=>'checkbox','value' => $app['Application']['description'],'label'=>$app['Application']['description']));



    }


<div class="checkboxes"> 
    <input type="hidden" name="data[Group][Application]" id="GG_" value="0"/><input type="checkbox" name="data[Group][Application]"  id="GG" value="GG"/><label for="GG">GG</label><input type="hidden" name="data[Group][Application]" id="BS_" value="0"/><input type="checkbox" name="data[Group][Application]"  id="BS" value="BS"/><label for="BS">BS</label>  <div>
</div>
    <input type="hidden" name="data[Group][Grant]" id="GroupGrant_" value="0"/><input type="checkbox" name="data[Group][Grant]"  style="float: left; display: inline" value="Edit Weather" id="GroupGrant"/><label for="GroupGrant">Edit Weather</label><input type="hidden" name="data[Group][Grant]" id="GroupGrant_" value="0"/><input type="checkbox" name="data[Group][Grant]"  style="float: left; display: inline" value="Edit Traffic" id="GroupGrant"/><label for="GroupGrant">Edit </label>       




        </div>

not sure where the hidden field is coming from. thanks


回答1:


this is a cake fallback in case you don't select the checkbox and post the form in order for the validation to jump in. in this case php would not submit anything for this field (not even an empty string). therefore cake has found a smart workaround to overcome this issue.

similar thing with radio buttons btw.




回答2:


Even though there is a hidden field we can make it disabled when we submit the form, so that it won't appear in the submitted data.. You need to write in the following way..

echo $this->Form->input('Application', array('type'=>'checkbox', 'id'=>$app['Application']['description'], 'div'=>false,'type'=>'checkbox','value' => $app['Application']['description'],'label'=>$app['Application']['description'],'hiddenField'=>false));


来源:https://stackoverflow.com/questions/10049917/cakephp-checkbox-is-showing-extra-hidden-field

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