Forms 获取复选框组值
这真让我抓狂。这是如此简单和容易,但我无法找出它的错误 我希望在控制器中填充复选框值(用于测试目的) 这是我的表格Forms 获取复选框组值,forms,codeigniter,Forms,Codeigniter,这真让我抓狂。这是如此简单和容易,但我无法找出它的错误 我希望在控制器中填充复选框值(用于测试目的) 这是我的表格 <a href='#' name='submitForm'>submit the form</a> //I have jquery attached to this tag and will submit the form when user clicks it echo form_open('test/show'); echo form_chec
<a href='#' name='submitForm'>submit the form</a>
//I have jquery attached to this tag and will submit the form when user clicks it
echo form_open('test/show');
echo form_checkbox('checkbox[]','value1');
echo form_checkbox('checkbox[]','value2');
echo form_checkbox('checkbox[]','value3');
echo form_checkbox('checkbox[]','value4');
echo "<input type='text' name='text1' value='ddd'>";
echo form_close();
//My controller test
public function show(){
$data1=$this->input->post('text1');
//I can get text1 value from input box
$data2=$this->input->post('checkbox');
//it keeps giving me undefined index 'checkbox'
$data3=$_POST['checkbox'];
//same error message
//WTH is going on here!!!!!
}
//我将jquery附加到此标记,并将在用户单击它时提交表单
echo form_open(“测试/显示”);
回显表单_复选框(“复选框[]”,“值1”);
回显表单_复选框(“复选框[]”,“值2”);
回显表单_复选框(“复选框[]”,“值3”);
回显表单_复选框(“复选框[]”,“值4”);
回声“;
回声形式_close();
//我的控制器测试
公共活动展览({
$data1=$this->input->post('text1');
//我可以从输入框中获取text1值
$data2=$this->input->post('checkbox');
//它一直给我未定义的索引“复选框”
$data3=$_POST['checkbox'];
//相同的错误消息
//这里发生了什么事!!!!!
}
请帮忙。这东西快把我逼疯了!谢谢
更新:
谢谢你的帮助。更准确地说,我的提交按钮是一个
标记,位于表单
标记之外。似乎我必须在我的表单中包含
标记才能使它们工作。这是真的吗 如果复选框未选中,则不会提交任何数据,因为它们被认为不成功()
如果你真的勾选并提交,它会工作的——事实上,我刚刚测试过它
您需要在函数中包装对$\u POST
的调用
if( isset( $_POST['checkbox'] ) ) {}
调用$this->input->post('checkbox')
不应给出未定义的索引错误,因为该方法处理这种情况。Input::post()
方法返回false或复选框的值
编辑--
为了响应您对问题的修改,您必须使用input
类型的元素,并将type
属性设置为submit,以便在不使用Javascript等的情况下提交表单数据。此按钮必须位于您要提交的
中
<input type="submit" value="Submit">
$this->input->post('anythis')
永远不会给您“未定义的索引”,它将始终返回FALSE或值。“你的问题有点不对。@Madmartigan我从codeigniter错误报告中得到了错误,不知道为什么。另外,请看我的更新说明。谢谢+1.
// Standard Javascript
<form name="myform"...
<a onclick="javascript:document.myform.submit();" href="javascript:void(0)">Submit</a>
// jQuery
$('#my-a-tag-submit-button').live( 'click', function() {
$('#my-form').submit();
}