我使用Datatables提交调查问题的答案。每个问题都在新的页面中,下一个是用“下一步”按钮看到的。我想只有一个提交按钮,它必须出现在所有问题的末尾。在我的代码中,它在桌子下面,并且始终可见。我最大的问题是,这个提交按钮只能在db中插入最后一个问题,但不是所有问题。 请你帮帮我吗? :) 我的看法是:如何使用Datatables提交表单
<html>
<head>
<link rel="stylesheet" href="//cdn.datatables.net/1.10.5/css/jquery.dataTables.min.css" type="text/css" />
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//cdn.datatables.net/1.10.5/js/jquery.dataTables.min.js"></script>
<script>
\t $(document).ready(function() {
$('#example').dataTable({
"pagingType": "simple",
"lengthMenu": [[1], [1]],
"bSort": false,
"language": {
"paginate": {
"previous": true
}
}
});
});
</script>
</head>
<body>
<?php
echo form_open('index/survey_fill/' .$survey_id ); ?>
<table id="example" >
<thead>
\t <tr><th>Question</th></tr>
</thead>
<tbody>
<?php
\t echo validation_errors();
\t foreach ($survey as $row)
\t { \t
\t \t
\t \t ?>
\t \t <tr>
\t
\t \t <td>
\t \t <?php echo "$row->question"; ?><br/>
\t \t <?php echo "<input type='hidden' name='question_id' value='$row->question_id' />"; ?>
\t \t $data=array(
\t \t \t 'name' => 'answer['.$row->question_id.']',
\t \t \t 'value' => '5'
\t \t);
echo form_radio($data);
\t \t echo " 5 ";
\t \t $data=array(
\t \t \t 'name' => 'answer['.$row->question_id.']',
\t \t \t 'value' => ' 4'
\t \t);
\t \t echo form_radio($data);
\t \t echo " 4";
</td></tr>
\t <?php
\t }
?> \t
\t \t
\t </tbody>
</table>
<?php echo "<input type='hidden' name='question_id' value='$row->question_id' />"; ?>
<input type="submit" id="button" name = "submit" value="Submit" class="btn btn-success">
</form>
</div>
</body>
</html>
我的模式是:
public function survey_fill()
{
$answers=($this->input->post('answer'));
if (null !==($this->input->post('submit'))) {
$date = new DateTime("now");
foreach($answers as $question_id=>$answer)
{
$data = array(
'user_id'=>$this->session->userdata['user_id'],
'question_id'=>$question_id,
'answer'=>$answer,
'created_at'=>$date->format('Y-m-d H:i:s')
);
$this->db->insert('survey_answers', $data);
}
if($this->db->affected_rows() > 0)
{
return true;
}
return false;
}
}