Array
(
[Users] => Array
(
[username] => test
[email] => test@gmail.com
[password] => 098f6bcd4621d373cade4e832627b4f6
)
)
Debug info outputs what it should output:
users model
<?php
class Users extends AppModel
{
public $name = "Users";
public $validate = array(
'address' => array(
'emailFieldsMatch' => array(
'rule' => 'emailFieldsMatch',
'message' => 'Email Fields do not match.',
),
'emailValid' => array(
'rule' => 'emailValid',
'message' => 'Invalid Email Address',
),
),
'username' => array(
'rule' => 'notEmpty',
'message' => 'Field Required',
),
'pass' => array(
'rule' => 'passFieldsMatch',
'message' => 'Password Fields do not match.',
),
);
public function beforeSave()
{
if(!empty($this->data) && isset($this->data['Users']['action']) &&
($this->data['Users']['action'] == 'register'))
{
//actual email address field.
$this->data['Users']['email'] = $this->data['Users']['address'][1];
$this->data['Users']['password'] = md5($this->data['Users']['pass']
[1]);
//we don't need these variables anymore delete it before cake
attempts to save it
unset($this->data['Users']['address']);
unset($this->data['Users']['action']);
unset($this->data['Users']['pass']);
pr($this->data);
}
}
/** -------------------------------------
Custom Validation Rules
------------------------------------- **/
public function passFieldsMatch($data)
{
return $data['pass'][1] == $data['pass'][2];
}
public function emailFieldsMatch($data)
{
return $data['address'][1] == $data['address'][2];
}
public function emailValid($data)
{
$regex = "/^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*
[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/";
return preg_match($regex, $data['address'][1]);
}
}
?>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment