hello guys.I have problem.I need to validate form field.I put validation rule bt it not validated.
Iam confuse about it.
this is my model rule()
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('username, preferred_name', 'length', 'max'=>45),
array('password, salt, first_name, last_name', 'length', 'max'=>100),
array('status', 'length', 'max'=><img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />,
array('gender', 'length', 'max'=>1),
array('date_of_birth', 'safe'),
array('first_name', 'required','message'=>'Cannot be Empty', 'on'=>'update'),
//array('first_name,last_name,preferred_name,date_of_birth','required','message'=>'Cannot be Empty'),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array( 'first_name','safe', 'except'=>'update'),
array('id, username, password, salt, status, last_name, preferred_name, gender, date_of_birth', 'safe', 'on'=>'search'),
);
}
here is my controller
public function actionUpdategeneral() {
// $users=new Users;
$usermodel = Users::model ()->findByPk ( Yii::app ()->user->id );
// $usermodel= Users::model()->find('id=:id',array(':id'=>Yii::app()->user->id));
// $this->performAjaxValidation ( $usermodel );
if (isset ( $_POST ['Users'] )) {
$usermodel->attributes = $_POST ['Users'];
//if ($usermodel->validate()){
if( $usermodel->save ()){
//Yii::app()->user->setFlash('success', 'Your Details Have been Updated Successfully.');
$this->redirect ( 'index' );
//
//
}
}
}
here is my view
<?php
$form = $this->beginWidget ( 'CActiveForm', array (
'id' => 'user_form',
'action' => Yii::app ()->createUrl ( '/profile/updategeneral' ),
'htmlOptions' => array (
'class' => 'contact_form profile_tab_form'
),
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation' => false,
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
) );?>
<?php echo $form->errorSummary($users); ?>
<fieldset class="left">
<div class="">
<?php echo $form->labelEx($users, 'first_name'); ?>
<div class="block">
<?php echo $form->textField($users, 'first_name', array('style' => 'width:261px;')); ?>
</div>
<?php echo $form->error($users, 'first_name'); ?>
</div>
<div class="">
<?php echo $form->labelEx($users, 'gender'); ?>
<?php echo ZHtml::enumDropDownList( $users,'gender' ,array('class' => 'dropDownBox')); ?>
<?php //echo $form->textField($users, 'gender', array('style' => 'width:261px;')); ?>
<?php echo $form->error($users, 'gender'); ?>
</div>
<div class="">
<?php echo $form->labelEx($users, 'date_of_birth'); ?>
<div class="block">
<?php echo $form->textField($users, 'date_of_birth', array('style' => 'width:261px;')); ?>
</div>
<?php echo $form->error($users, 'date_of_birth'); ?>
</div>
</fieldset>
<fieldset class="right">
<div class="">
<?php echo $form->labelEx($users, 'last_name'); ?>
<div class="block">
<?php echo $form->textField($users, 'last_name', array('style' => 'width:261px;')); ?>
</div>
<?php echo $form->error($users, 'last_name'); ?>
</div>
<div class="">
<?php echo $form->labelEx($users, 'preferred_name'); ?>
<div class="block">
<?php echo $form->textField($users, 'preferred_name', array('style' => 'width:261px;')); ?>
</div>
<?php echo $form->error($users, 'preferred_name'); ?>
</div>
</fieldset>
<fieldset style="clear: both;">
<div class="">
<?php echo CHtml::submitButton($users->isNewRecord ? 'Update' : 'Update'); ?>
</div>
</fieldset>
<?php $this->endWidget(); ?>
</div>
please help me.