我需要一些帮助。我有这个表单组:这是视图:
<?php echo form_open('admin/posts/post/'.$post->id); ?>
// other fields here...
<div class="form-group">
<label for="" class="col-sm-2">Visible</label>
<div class="col-sm-10">
<div class="onoffswitch">
<?php
$visible = ($post->visible) ? $post->visible : $this->input->post('visible');
$visible_data = array(
'class' => 'onoffswitch-checkbox',
'id' => 'visible',
'checked' => ($visible == '1') ? true : false,
'name' => 'visible',
'value' => ($post->visible) ? $post->visible : $this->input->post('visible'),
);
?>
<?php echo form_checkbox($visible_data); ?>
<label class="onoffswitch-label" for="visible">
<div class="onoffswitch-inner"></div>
<div class="onoffswitch-switch"></div>
</label>
</div>
</div>
</div>
// more fields ...
<?php echo form_close(); ?>
这是控制器
public function post($id){
$this->data['post'] = $this->post_model->get($id);
$this->form_validation->set_rules($this->post_model->rules);
if ($this->form_validation->run() === true) {
var_dump($this->input->post('visible')); //not getting anything from the visible field
// store data in database and redirect
$this->post_model->save($id);
}
// load the view
$this->load->view('admin/post/edit');
}
基本上,这可以用作开/关开关按钮。问题是当我单击提交按钮时,它不会将字段 ( $this->input->post('visible')
) 的 $_POST 数据发送到我的模型以便将其存储在数据库中。
有什么想法有什么问题,应该如何解决?