Form Will Not Validate On Server Side, But Client Validation Is Ok

Please help. My form will not validate on the server side and I cannot figure out why. I’m trying to create a HelpDesk system to log cases into our database.

I have a view that contains a CJuiTab widget. Inside one of the tabs, I have a form, which loads, via AJAX, a renderPartial of a controller action called CaseEntry and a view file called _case.

In my form, enableAjaxValidation is set to true but does not work. enableClientValidation is also enabled and seems to work just fine.

The goal is for the user save this form and get back a confirmation response in the form tab. My tab loads fine, data is populated and if I print_r($_POST) in the controller, I can see the data is correct. The problem is that even though client side validation appears to be working fine (ie: I get errors when user inputs a letter in the case_number field), when I submit the form it never validates.

I have included the code related to this issue. Can anybody point me in the right direction? Am I missing something?

Here is the code for the parent view conatining the CJUITabs widget:




<?php

	//-------------- parent view with CJUITabs container (case) ----------------

	$this->widget('zii.widgets.jui.CJuiTabs', array(

		'Case'=>array('ajax'=>$this->createUrl('helpDesk/caseEntry',array('case_number'=>$model->case_number))),

		//other tabs here

	));

?>



This is the AJAX-loaded form loaded into my tab:




<?php

	//-------------- tab content (_case) ----------------


	if($model->case_number != null){        

        		$model = $model->getCase();        

		//model is now an existing case

    	}


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

                'id'=>'case_form',

                'enableAjaxValidation'=>true,                

                'enableClientValidation' => true,

                'clientOptions' => array(

                    'validateOnChange' => true,

                    'validateOnSubmit' => true,                    

                ),                

                'focus'=>array($model,'case_number')   

            ));	

	echo $form->errorSummary($model); 

?>

<div class="button_bar">

            <?php                

                echo CHtml::ajaxSubmitButton($model->isNewRecord ? 'Save' : 'Update',                        

                        $this->createUrl('HelpDesk/CaseEntry',array('case_number'=>$model->case_number)),                        

                        array(

                            'update'=>'#tabs_tab_0',

                            'data'=>'js:$("#case_form").serialize()',

                    ));

            ?>        

</div>

<div class="row">

	<?php echo $form->label($model,'case_number') ?>

	<?php echo $form->textField($model,'case_number') ?>                        

	<?php echo $form->error($model,'case_number') ?>

</div>

<div class="row">                            

	<?php echo $form->label($model,'serial_number') ?>                       

	<?php echo $form->textField($model,'serial_number') ?>

	<?php echo $form->error($model,'serial_number') ?>

</div>

… other fields here ...

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



These are the controller actions where I am having the problem:




<?php

	//-------------- controller ----------------


	public function actionCase()

	{

		$model = $this->getModel();

		$case = $model->getCase();

		$this->render('case',array('model'=>$model));

	}




	public function actionCaseEntry()

	{

           	$model = $this->getModel();

           

	            if(Yii::app()->getRequest()->getIsAjaxRequest())

		{

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

			{					

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


				/*********** HERE  IS WHERE STUFF ISN'T WORKING: *************/

				if($model->validate())

				{

					echo "<div class='flash-success'>validation successful</div>";

					//$model->save();

					//redirect can go here

				}

				else

				{

					echo "<div class='flash-error'>validation failed</div>";

					print_r($model->getErrors());

				}

			}

		}

		$this->renderPartial('_case',array('model'=>$model),false,true);

	}


	public function getModel()

	{

		$case_number = (isset($_REQUEST['case_number'])) ? $_REQUEST['case_number'] : null;

		$model = new HelpDesk();

		$model->case_number = $case_number;            

		return $model;

	}	

?>



Finally, here is the model where my rules are defined:




<?php

	//-------------- model ----------------

	class HelpDesk extends CActiveRecord

	{

        public $case_number;

		public function rules()

		{

			return array(

			   array('case_number','numerical','integerOnly'=>true),

			   array('serial_number','safe'),

                        );

			//other rules will go here

		}

		public function getCase()

		{

			$criteria = new CDbCriteria;

			$criteria->select = array(

				'*','incident_id AS case_number',

			);

			$criteria->condition='incident_id = :case_number';

			$criteria->params=array(':case_number'=>$this->case_number);            

			$open = HelpDesk::model()->find($criteria);

			return $open;

		}

                

        }

?>