简体   繁体   中英

How to not receive the same validation message twice - Yii Rules

I've recently implemented my own error function using the Yii rules. Within the function I am checking whether the phone number and pin given are the exact phone number and pin I would like. (I need the pin and the phone number together because I will be checking whether together they are valid on another server). However, for now whenever I input something that is an error, I receive my manually inputted error twice. Here is the code for the custom rule

/** 
*  
* this function checks whether the given msisdn and pin number create a valid tigo cash account
* @param $array that takes in two arguments, the first argument is the msisdn, and the second 
* is the pin 
* @return returns an error if the pin and msisdn do not validate with the Tigo server 
*/ 
public function tigoValidate($array)
{   
    // clarify the origins of the variable 
    $msisdn = $array[0];
    $pin = $array[1];
    // if the pin does not equal this and the pin does not equal that 
    if($array[0] !== '250728424547' && $array[1] !== '1463')
    {
        $this->addError($array, 'your number-pin combination does not work!');      
    }

}

and here is how I am calling it in the rules

public function rules()
{
    return array(
        array(array('msisdn', 'pin'), 'tigoValidate')
    );
}

When input the wrong msisdn or pin I get back the "Your pin-number combination does not work' error twice. I think this has to do with me passing the msisdn and pin separately - is there any way that I can only have the program display the error once?

I think your rule is not correct beacuse you need to insert the array into quotes

public function rules()
{
    return array(
        array("array('msisdn', 'pin')", 'tigoValidate')
    );
}

http://www.yiiframework.com/wiki/56/#hh0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM