mercredi 1 avril 2015

How to submit a form using Data tables

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. How should I use submit form in Data Tables? I want submit button to be seen finally. Here's my view:





<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,

"language": {
"paginate": {
"previous": 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
}
?>

<tr><td><input type="submit" id="button" name = "submit" value="Submit">

<?php echo form_close(); ?>

</td></tr>

</tbody>
</table>

</div>
</body>
</html>



My model is:





<?php
class User_model extends CI_Model {


public function __construct() {
parent:: __construct();
$this->load->database();
$this->load->helper('array');

}
public function survey_show() {

$this->db->select('*');
$this->db->from('survey_questions');
$this->db->where('survey_id', $this->uri->segment(3));
$result=$this->db->get();

return $result->result();
}
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;
}
}



Aucun commentaire:

Enregistrer un commentaire