1
我想請一些幫助。我有這種形式的基團: 這是視圖:
<?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');
}
Basicly這個作品作爲on/off switch button。問題是,當我點擊提交按鈕時,它不會將字段($this->input->post('visible')
) 的$ _POST數據發送到我的模型,以便將其存儲在數據庫中。
任何想法有什麼不對,應該如何解決?