我试图在此代码中获取我的复选框(1 =已选中或0 =取消选中)的值(这是我的代码点火器中的视图):
<input type="checkbox" name="Visible" class="text" value="1"
<?php $visible = isset($_POST['Visible'])? '1' : '0';?>/>
我的问题是:
value="1"
的功能是什么?我正在搜索此案例,但人们只是说我们总是需要添加值。谢谢你,我知道这是一个非常简单的问题,但是自昨天以来它一直给我一些错误@ _ @
这是代码的重要部分: 添加功能用于保存(在控制器中):
function add(){
$data['title'] = 'Tambah Category baru';
$data['action'] = site_url('category/add');
$data['link_back'] = anchor('category/index/', 'Back to Category list', array('class'=>'back'));
//bedakan add/update
$data['validate'] = 'add';
$this->_set_rules();
//run validation
if($this->form_validation->run() == false){
$data['message'] = '';
$data['title'] = 'Add new Category';
//$data['message'] = '';
$data['category']['ID_category'] = '';
$data['category']['ID_user'] = '';
$data['category']['Nama_category'] = '';
$data['category']['Description'] = '';
$data['category']['Visible'] = '';
$data['link_back'] = anchor('category/index/', 'Lihat daftar Category', array('class'=>'back'));
$this->load->view('category_form_v', $data);
}
else{
//save data
$category = array('ID_category'=>$this->input->post('ID_category'),
'ID_user'=>'TESTING USER',
'Nama_category'=>$this->input->post('Nama_category'),
'Description'=>$this->input->post('Description'),
'Visible'=>($$this->input->post('Visible') !== false ? '1' : '0'),
'tgl_buat '=>date('Y-m-d H:i:s'));
$ID_category = $this->category_m->save($category);
$this->validation->ID_category = $ID_category;
redirect('category/index/add_success');
}
}
我的HTML代码(在视图中):
<td valign="top">Visible<span style="color:red;">*</span></td>
<td><input type="checkbox" name="Visible" class="text"/>
答案 0 :(得分:0)
改为使用input library。
特别是帖子功能
$visible = ($this->input->post('Visible') !== false ? 1 : 0);
function add(){
$data['title'] = 'Tambah Category baru';
$data['action'] = site_url('category/add');
$data['link_back'] = anchor('category/index/', 'Back to Category list', array('class'=>'back'));
//bedakan add/update
$data['validate'] = 'add';
$this->_set_rules();
//run validation
if($this->form_validation->run() == false){
$data['message'] = '';
$data['title'] = 'Add new Category';
//$data['message'] = '';
$data['category']['ID_category'] = '';
$data['category']['ID_user'] = '';
$data['category']['Nama_category'] = '';
$data['category']['Description'] = '';
$data['category']['Visible'] = '';
$data['link_back'] = anchor('category/index/', 'Lihat daftar Category', array('class'=>'back'));
$this->load->view('category_form_v', $data);
}
else{
//save data
$category = array('ID_category'=>$this->input->post('ID_category'),
'ID_user'=>'TESTING USER',
'Nama_category'=>$this->input->post('Nama_category'),
'Description'=>$this->input->post('Description'),
'Visible'=>($this->input->post('Visible') !== false ? '1' : '0'),
'tgl_buat '=>date('Y-m-d H:i:s'));
$ID_category = $this->category_m->save($category);
$this->validation->ID_category = $ID_category;
redirect('category/index/add_success');
}
}