daily pastebin goal
6%
SHARE
TWEET

Untitled

a guest Jun 18th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * CakePHP: Add a custom function to model field validation.
  3.  * In this case it makes sure that an email address can occur multiple times,
  4.  * but it can only occur with another where column 'site_name' equals $foo
  5.  * once
  6.  */
  7. var $validate = array(
  8.         'email' => array(
  9.             'form' => array(
  10.                     'rule' => 'email',
  11.                     'message' => 'Please enter a valid email address',
  12.                     'allowEmpty' => false,
  13.             'last' => true
  14.             ),
  15.             'unique' => array(
  16.                 'rule' => array('checkUnique'),
  17.                 'message' => 'You are already registered',
  18.                 'allowEmpty' => false,
  19.             'last' => true,
  20.                     'on' => 'create' // only use this rule on field creation, not update
  21.             )
  22.     )
  23. );
  24.  
  25. function checkUnique($arrEmail) {
  26.         $intCount = $this->find('count', array(
  27.             'conditions' => array(
  28.             'site_name' => $foo,
  29.             'email' => $arrEmail['email']
  30.         )));
  31.        
  32.         return $intCount == 0 ? true : false;
  33.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top