Re Rendering a view with new data

I’m trying to make a survey page from a database. The questions are loaded onto the view based on what section of questions the user is at. For some reason, whenever I click “next” the page is re-rendered with out getting the previously entered data. I set up a couple echo statements in the controller to try to trace what is going on, but I have had no luck. The only two that show are the ones that say “page not created” and “initial render”. Does any one have any ideas on what might be happening here?

Thanks!

Controller List Function




 public function actionList()

        {

                $skills = array(

                        1=>'skill_response1',

                        2=>'skill_response2',

                        3=>'skill_response3',

                        4=>'skill_response4',

                        5=>'skill_response5',

                        6=>'skill_response6',

                        7=>'skill_response7',

                        8=>'skill_response8',

                        9=>'skill_response9'

                );


                $import = array(

                        1=>'import_response1',

                        2=>'import_response2',

                        3=>'import_response3',

                        4=>'import_response4',

                        5=>'import_response5',

                        6=>'import_response6',

                        7=>'import_response7',

                        8=>'import_response8',

                        9=>'import_response9'

                );


                if(isset($_REQUEST['id']))

                        $user = User::model()->findByPk($_REQUEST['id']);

                else

                        $this->redirect(array('survey/user',));


                if(isset($_REQUEST['created'])) echo $created;

                        else

                                echo "not created";


                //variable determines if the page has been created yet

                if(isset($_REQUEST['created']))

                {

                        $temp = new CDbCriteria;

                        $temp->addSearchCondition('section',$sec->ID,true, 'AND');


                        $number = count(Questions::model()->findAll($temp));


                        $continue = true;


                        $errorList = 'Please answer all questions completely: </br>';

                        //error handling - checks for uncompleted questions and adds to error list

                        for($i = 1; $i <= $number; $i++)

                        {

                                if(!isset($_REQUEST[$skills[$i]]))

 {

                                        $errorList.= 'Question '.$i.' Skill response<br />';

                                        $continue = false;

                                }

                                if(!isset($_REQUEST[$import[$i]]))

                                {

                                        $errorList.= 'Question '.$i.' Importance response<br />';

                                        $continue = false;

                                }

                        }


                        if($continue)

                        {

                                for($j = 1; $j < $number; $j++)

                                {

                                        $results = new Results();

                                        $results->user_id = $user->id;

                                        $results->section_id = $_REQUEST['page'];

                                        $results->question_id = $j;

                                        $results->skill_rating = $_REQUEST[$skills[$j]];

                                        $results->importance_rating = $_REQUEST[$import[$j]];

                                        $results->save();

                                }


                                $section=Section::model()->findByPk($_REQUEST['page'] + 1);


                                $this->render('survey/list',array('sec'=>$section,'id'=>$user->id,));

                                echo "page completed";

                        }

                        else

                        {

                                //Error stuff goes here

                                Yii::app()->user->setFlash('contact', $errorList);

                                //$this->refresh();//'sec'=>$section,'id'=>$user->id,'questions'=>$_REQUEST['questions'],));

                                echo "error reached";

                        }


                }

                else

                {

                        if(!isset($_REQUEST['page']))

                                $section=Section::model()->findByPk(0);

                        else

                                $section=Section::model()->findByPk($_REQUEST['page']);




                        $criteria = new CDbCriteria;

                        $criteria->addSearchCondition('section',$section->ID, false, 'AND');

                        $questions=Questions::model()->findAll($criteria);


                        $number = count($questions);

                        echo "Render Initial";

                        $this->render('list',array('sec'=>$section,'id'=>$user->id,'questions'=>$questions,'number'=>$number));

                }

        }



List view




<?php

        $this->pageTitle=Yii::app()->name.' - Assessment Questions';

        $created = true;

?>


<div class="fullPage">

        <div class="form">

                <h2><?php echo 'Section '.($sec->ID+1).' - '.$sec->section_name; ?></h2>

                <?php $form=$this->beginWidget('CActiveForm'); ?>

                <input type="hidden" name="sec" value="<?php echo $sec->ID; ?>"/>


                <?php

                        echo 'error stuff goes here';

                        echo Yii::app()->user->getFlash('contact');

                        if(isset($error)) {echo $error(0);}

                        echo '<br />number of questions: '.$number;

                        echo '<br />'.$sec->ID;

                ?>

                <table class="questions">

                        <tr>

                                <th class="section1"></th>

                                <th class="section2"><p align="center"><b>Skill Level Now</b></p></th>

                                <th class="section3"><p align="center"><b>Importance for my Teaching<br />Now or in the Future</b></p></th>

                        </tr>

                        <tr>

                                <td class="section1"></td>

                                <td class="section2"><div class="col1">Needs Improvement</div><div class="col2">Excellent</div>

                                        <br /><div class="line"></div></td>

                                <td class="section3"><div class="col1">Not<br />Important</div><div class="col2">Important</div>

                                        <br /><div class="line"></div></td>

                        </tr>

                        <tr>

                                <td class="section1"><b>Questions</b></td>

                                <td class="section2">1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                                        3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>

                                <td class="section3">1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                                        3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>

                        </tr>


                        <?php foreach( $questions as $n=>$question): ?>

                                <tr>

                                        <td class="section1">

                                                <?php echo $question->order.': '.$question->question; ?>

                                        </td>

                                        <td class="section2">

                                        <?php for($i=1; $i<9; $i++) {

                                                if($i <5)

                                                        echo '&nbsp;<input type="radio" name="skill_response'.$question->order.'" value="'.$i.'">&nbsp&nbsp&nbsp&nbsp;&nbsp;&nbsp;';

                                                else

                                                        echo '&nbsp;<input type="radio" name="import_response'.$question->order.'" value="'.($i-4).'">&nbsp&nbsp&nbsp&nbsp;&nbsp;';

                                                if($i === 4)

                                                        echo '</td><td class="section3">';

                                        } ?>

                                        </td>

                                </tr>

                        <?php endforeach; ?>

                </table>

                <div class="button">

                        <?php echo CHtml::submitButton('Next'); ?>

                </div>

                <div class="clear"></div>

                <?php $this->endWidget(); ?>

        </div>

</div>




Where did you set the input in the view that should result in $_REQUEST[‘created’]?

Figured it out. The problem was actually in the controller function for a previous view, I needed to use a redirect instead of a render and it worked fine.

Donnut: Sorry forgot to change that back before I posted this. It was set after the beginWidget, originally, can’t remember why I tried moving it for the life of me. Thanks though. I’d take this down, but I don’t think you can delete posts…