Submit button does not work in Data Tables
Submit button does not work in Data Tables
miss89
Posts: 3Questions: 2Answers: 0
Hello everybody, I'm using data tables to show questions from a survey. Questions are shown one per page. When user click the "next" button, he sees the next question, and finally he sees submit button. But it does not work, it does not send the form. Here's my code:
<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>
$(document).ready(function() {
$('#example').dataTable( {
"pagingType": "simple",
"lengthMenu": [[1], [1]],
"bSort": false
} );
} );
</script>
</head>
<body>
<br/><br/>
<?php
$survey_id = $this->uri->segment(3);
<table id="example" >
<thead>
<tr><th>Въпрос</th></tr>
</thead>
<tbody>
<?php
echo validation_errors();
foreach ($survey as $row)
{
$row->question_id=$this->uri->segment(4);
$question_id=$this->uri->segment(4);
?>
<tr>
<?php
$attributes = array('id' => 'myform');
echo form_open('index/survey_fill/' .$survey_id , $attributes); ?>
<td>
<?php echo "$row->question"; ?><br/>
<?php echo "<input type='hidden' name='question_id' value='$row->question_id' />"; ?>
$data=array(
'name' => 'answer['.$row->question_id.']',
'value' => '5'
);
echo "<input type='hidden' name='survey_id' value='$row->survey_id'>"; ?>
<?php echo "<input type='hidden' name='question_id' value='$row->question_id' />";
echo form_radio($data);
echo "5 ";
$data=array(
'name' => 'answer['.$row->question_id.']',
'value' => ' 4'
);
echo form_radio($data);
echo " 4";
</td></tr>
<?php
}
<?php
>
?>
<?php echo form_close(); ?>
</td></tr>
</tbody>
</table>
</div>
</body>
</html>
My model is:
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;
}
}
How should submit be done to send this from?
This discussion has been closed.