Form Submit

View Code


<div class="form">

<?php 

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

        array(

            'enableClientValidation'=>true,

            'id'=>'attendance-form',

            'action'=>array('getEmployeeData'),

            'clientOptions'=>array('validateOnSubmit'=>true,'validateOnChange'=>true)

        ));

    ?>

 

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

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

    <div class="row">

            <?php echo $form->labelEx($model_one,'employee_full_name'); ?>

            <?php 

                    $this->widget('CAutoComplete',

                        array(

                            //name of the html field that will be generated

                            'model'=>$model_one,

                            'id'=>'SupervisorAttendance_employee_full_name',

                            'name'=>'employee_full_name', 

                            'url'=>array('attendance/autoCompleteLookup'), 

                            'max'=>10, //specifies the max number of items to display

                            'minChars'=>2,//specifies the number of chars that must be entered before autocomplete initiates a lookup

                            'delay'=>100, //number of milliseconds before lookup occurs

                            'matchCase'=>false, //match case when performing a lookup?

                            //any additional html attributes that go inside of the input field can be defined here

                            'htmlOptions'=>array('size'=>'40'), 

                            'methodChain'=>".result(function(event,item){\$(\"#user_id\").val(item[1]);})",

                        )

                    );

                    echo CHtml::hiddenField('user_id');

                ?>

                <?php echo $form->error($model_one,'employee_full_name'); ?>

	</div>

    

    <div class="row submit">

        <?php echo CHtml::submitButton('Get Employee Data'); ?>

    </div>

 

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

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

Controller Action


public function actionGetEmployeeData($id='')

        {

            $model = new TblBasicEmployeeDetails;

            $model_one = new SupervisorAttendance;//for model class SupervisorAttendance

            

            if($id == ''){

                // collect user input data

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

                {

                    echo 'inside form submit';die();

                    $model_one->attributes=$_POST['AttendanceForm'];

                    // validate user input and redirect to the previous page if valid

                    if($model_one->validate())

                            echo 'validated';die();

                }else{

                    echo 'form not submitted';

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

                }

            }

}

My form is not submitting…it always enters else code…but if i take the post of my hidden field i get the value…what could be wrong?Please help




if(isset($_POST['SupervisorAttendance'])){

...

}


NOT


if(isset($_POST['AttendanceForm'])){


}



Because you don’t define $_POST[‘AttendanceForm’] and you use $model_one which is an instance of SupervisorAttendance model class

I changed to SupeervisorAttendance…still it aint working… :(

Below is my code for SupervisorAttendance


<?php


class SupervisorAttendance extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @return TblReportType the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'tbl_basic_employee_details';

	}

        

	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

            // NOTE: you should only define rules for those attributes that

            // will receive user inputs.

            return array(

                    array('employee_full_name', 'required')

            );

	}

}

?>




print_r($_POST);



to see what is inside it after you submit your form.