Hello all,
I'm trying to set up validation to check for existing values within
the beforeValidate() function. What I'm aiming for is to do a check to
make sure the username & email isn't already taken when the user is
signing up. But when the user is editing their info I don't want an
error thrown if they don't change other details but not their username
and/or email. Here's what I have that works for adding users.
function beforeValidate() {
if ($this->findByUsername($this->data[$this->name]['username'])) {
$this->invalidate('username_unique');
}
if ($this->findByEmail($this->data[$this->name]['email'])) {
$this->invalidate('email_unique');
}
return true;
}
This works fine when adding a user but it also runs when the user is
editing their details and doesn't change the username or email. So I
thought maybe I could do different logic for each action like:
if ($this->params['action'] == 'add') {
// do the above code
} else if ($this->params['action'] == 'edit') {
// check to see if username/email in $this->data is the same as the
existing records for the given $id
}
But that doesn't work, it doesn't run the invalidation logic within
the if statement, and also generates a notice:
Notice: Undefined property: User::$action in /cakeapp/models/user.php
on line 49
Any input on what i could do differently?
Thanks,
Byron
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---