/** * Verifies that the field beeing validated matches the value of the * field in the second parameter. If omitted and the field beeing * validated's name is NAME_verification, the value will be compared * to that of the NAME field. * * Examples: * * var $validate( * 'password_check' => array( * 'rule' => array('verifies', 'password'), * 'message' => 'The passwords don\'t match' * ), * 'email_verification' => array( * 'rule' => array('verifies'), * 'message' => 'The email addresses don\'t match' * ), * ) * * * The second case will verify automagically against the "email" field. * * By Vicente Aguilar * http://www.bisente.com/blog/2008/10/14/validar-campos-de-verificacion-en-cakephp/ */ function verifies($data, $field=null) { $keys = array_keys($data); $key = $keys[0]; if(!is_string($field)) { if( ($pos = strpos($key, "_verification")) === FALSE ) { return FALSE; } $field = substr($key, 0, $pos); } return ($data[$key] == $this->data[$this->name][$field]); }