Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * CakePHP: Add a custom function to model field validation.
- * In this case it makes sure that an email address can occur multiple times,
- * but it can only occur with another where column 'site_name' equals $foo
- * once
- */
- var $validate = array(
- 'email' => array(
- 'form' => array(
- 'rule' => 'email',
- 'message' => 'Please enter a valid email address',
- 'allowEmpty' => false,
- 'last' => true
- ),
- 'unique' => array(
- 'rule' => array('checkUnique'),
- 'message' => 'You are already registered',
- 'allowEmpty' => false,
- 'last' => true,
- 'on' => 'create' // only use this rule on field creation, not update
- )
- )
- );
- function checkUnique($arrEmail) {
- $intCount = $this->find('count', array(
- 'conditions' => array(
- 'site_name' => $foo,
- 'email' => $arrEmail['email']
- )));
- return $intCount == 0 ? true : false;
- }
Add Comment
Please, Sign In to add comment