Yii Validation Rule Issue

I have a problem in yii validation rule, I make a signup form with couponcode for my product. When user enter a coupon code I want to check this couponcode is exist in coupon table or not,but problem is it,I want when user enter couponcode then my validation rule work otherwise if user can’t enter a couponcode this validation rule do not work,for user signup I have a user model and for coupon I have a coupon model, I am using this method in validation rules.


class User extends CActiveRecord

{

public $couponcode;


public function rules(){

.......

array('couponcode', 'isCouponCodeExist'),




}//end rules


public function isCouponCodeExist($attribute, $params)

{

$record = Coupon::model()->findByAttributes(array('couponcode' => $this->couponcode));


if($record === null){

$this->addError($attribute, 'Invalid Coupon');

return false;

}


return true;

}

} //class end

any suggesstion will be helpfull for me

Hi

put your code in action




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

		{

			echo CActiveForm::validate($model);

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

		}

hope it’s work…

Nope, can you understand my question?

anyone give me the answer please?

Hi

yes i can understand your issue


if($record === null){

change the


if(count($record)>0){

hope it’s solved

please see also link

http://help.discretelogix.com/php/yii/how-to-create-custom-validation-rule.htm