oligalma
(Marc Oliveras)
January 25, 2015, 9:16pm
1
I want to create a quiz with pagination. Therefore, I have the following structure:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'quiz-form',
'enableClientValidation'=>false,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>
<?php $this->widget('zii.widgets.CListView', array(
'ajaxUpdate'=>false,
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'template'=>"{items}\n{pager}",
)); ?>
<?php $this->endWidget(); ?>
Look at the image and you will understand better the situation:
6286
The problem is, when I click on a page number, the answers are not sent. I tried with the following jQuery but it’s not working:
$('.page').click(function(){
$('#quiz-form').submit();
});
Any ideas?
ronald58
(Yii)
January 25, 2015, 10:37pm
2
Perhaps:
$('.page a').click(function(){
$('#quiz-form').submit();
});
oligalma
(Marc Oliveras)
January 25, 2015, 11:12pm
3
this doesn’t work. In fact, the following “alert” works:
$('.page').click(function(){
alert('hello');
$('#quiz-form').submit();
});
ronald58
(Yii)
January 26, 2015, 12:07am
4
It would help to know what is actually being send. Without that info an educated guess might be to try:
$('.page').click(function(){
$('#quiz-form').submit();
return false;
});
oligalma
(Marc Oliveras)
January 26, 2015, 5:35am
5
it worked!
Now I have another problem. In the controller, I collect the POST data like this:
$this->paramKeys = array_keys($_POST);
$this->paramValues = array_values($_POST);
$i = 0;
foreach($this->paramKeys as $paramKey)
{
Yii::app()->session[$paramKey] = $this->paramValues[$i];
$i++;
}
If I set some answers and I click the same page number, the answers are set (this is correct). However, if I set some answers, click another page number and return back to the previous page, the answers are not set! Maybe this problem is related to sessions, since the variables of the session seem to disappear. I tried with $_SESSION but it happens the same.
ronald58
(Yii)
January 26, 2015, 8:00am
6
moginn:
it worked!
Now I have another problem. In the controller, I collect the POST data like this:
$this->paramKeys = array_keys($_POST);
$this->paramValues = array_values($_POST);
$i = 0;
foreach($this->paramKeys as $paramKey)
{
Yii::app()->session[$paramKey] = $this->paramValues[$i];
$i++;
}
If I set some answers and I click the same page number, the answers are set (this is correct). However, if I set some answers, click another page number and return back to the previous page, the answers are not set! Maybe this problem is related to sessions, since the variables of the session seem to disappear. I tried with $_SESSION but it happens the same.
You will have to take a look at your _view.php view and probably have to rewrite it to take the session parameters when set.
oligalma
(Marc Oliveras)
January 26, 2015, 8:16am
7
I already take the session parameters at my _view.php. Look:
<div style="border:1px solid black;margin:10px;padding:10px;">
<?php
echo CHtml::encode($data->title);
?>
<br/>
<?php
echo CHtml::radioButtonList($data->id, Yii::app()->session[$data->id], array(0 => 'false', 1 => 'true'));
?>
</div>
oligalma
(Marc Oliveras)
January 26, 2015, 9:17pm
8
Finally I solved the problem creating a temporary table. But does anyone know why I can’t use sessions?