I am trying to validate first name and last name on my user registration form. I have tested and the following works for existing users when updating their profile via the form. Both use the onBeforeSaveUser
event.
Any ideas why this wouldn't validate for registering users?
public function init()
{
craft()->on('users.onBeforeSaveUser', function(Event $event)
{
craft()->businessLogic_events->onBeforeSaveUser($event);
});
}
public function onBeforeSaveUser(Event $event)
{
$user = $event->params['user'];
if (empty($user->firstName))
{
$user->addError('firstName', Craft::t('Name cannot be empty.'));
$event->performAction = false;
}
if (empty($user->lastName))
{
$user->addError('lastName', Craft::t('Last Name cannot be empty.'));
$event->performAction = false;
}
}