can't submit a form

Hello guys I am creating a website with php and Yii framework. Right now I have created a admin module and created crud in this module, but it seems that I can’t create a record. what I have got for now is:


public function actionCreate()

    {

        $model=new GamesValidator;


        // Uncomment the following line if AJAX validation is needed

        $this->performAjaxValidation($model);

        /*

        if(isset($_POST['ajax']) && $_POST['ajax']==='games-form')

        {

            echo CActiveForm::validate($model);

            Yii::app()->end();

        }

        */

        if(isset($_POST['GamesForm']))

        {

            die('GamesForm is set'); // just to see if GamesForm has some value! but website never shows this massege, it shows just new form, which is my problem.

/*

            $model->attributes=$_POST['GamesForm'];

            if($model->validate()){

                echo ('This is only a test');

                return;

            } else {

                echo ('There was some error!');

                return;

            }

*/

        }


        $this->render('create',array(

            'model'=>$model,

        ));

    }

but it doesn’t show anything, website shows the form.php again like nothing was done at all. here is a little code from my view file:


<div class="form">


<?php $form=$this->beginWidget('CActiveForm', array(

    'id'=>'games-form',

    'enableAjaxValidation'=>true

)); ?>


<p class="note">Fields with <span class="required">*</span> are required.</p>


<?php echo $form->errorSummary($model); ?>

[..........................]


<div class="row buttons">

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

</div>


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


</div><!-- form -->

sorry I can’t post a full code it is too long.

so can you tell me what can be wrong?

Your problem is that [font=“Courier New”]$model[/font] is a [font=“Courier New”]GamesValidator[/font] instance, so instead of checking for [font=“Courier New”]$_POST[‘GamesForm’][/font] you should check for [font=“Courier New”]$_POST[‘GamesValidator’][/font]

Change your code to this.




      //demo 

      public function actionCreate()

    {

        $model=new GamesValidator;


        // Uncomment the following line if AJAX validation is needed

        $this->performAjaxValidation($model);

        /*

        if(isset($_POST['ajax']) && $_POST['ajax']==='games-form')

        {

            echo CActiveForm::validate($model);

            Yii::app()->end();

        }

        */

        if(isset($_POST['GamesValidator']))

        {

            

           // dont' use die(); but Yii::app()->end(); to exit and stop an action properly

           //die('GamesForm is set'); // just to see if GamesForm has some value! but website never shows this massege, it shows just new form, which is my problem.

            $model->attributes=$_POST['GamesValidator'];

            

            if($model->validate() && $model->save()) {

               // display simpel test that form has been safed

               echo 'Form has been safed';

               Yii::app()->end();

            }

            // output array containing all errors

            print_r($model->errors);

            Yii::app()->end();

        }


        $this->render('create',array(

            'model'=>$model,

        ));

    }

      



like mauriciorivera said you are checking the wrong post variable for the model data.

Also you call die before requesting save method on the model.

check this page and the chapters in this guid about forms and database these will help you get a better understanding on how to do crud operations or use gii and read true the generated code for a good example.