【发布时间】:2015-04-23 03:40:36
【问题描述】:
我想做一个简单的考试系统。
我们的想法是从下面的表格中提出一个问题,然后将值与下面的数据一起发送,因此我想将检查的输入发送到名为正确答案的列,并将两者发送到名为选项的列。
有什么想法吗?
我在视图中有这个表单
<form action="<?php echo base_url('home') ;?>" method="post">
<input type="text" name="question" placeholder="Enter question here"><br>
<label>choose the right answer</label><br>
<input type="radio" name="answer" value="first"> <input type="text" placeholder="first choice"><br>
<input type="radio" name="answer" value="second" checked><input type="text" placeholder="second choice"><br>
<input type="submit" value="sumbit" name="ask">
</form>
这是我的控制器:
class Home extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->model('exams_model') ;
}
public function index(){
$this->load->view('vieww') ;
if($this->input->post('ask')) {
$this->exams_model->add_question() ;
}
}
}
&这是模型:
class Exams_model extends CI_Model{
public function add_question(){
$data = array(
'question' => $this->input->post('question') ,
'choices' => $this->input->post('#') , // here i want to send both inputs ( the checked and non checked input
'right_answer' => $this->input->post('#') // i want to pass the checked input to the column right answer in the database
);
$insert = $this->db->insert('exams' , $data);
return $insert ;
}
}
【问题讨论】:
标签: php codeigniter radio