Extending user validation Hi I've created a plugin that has an action in the controller that looks at a user registration form when submitted and if the username is empty creates a unique username for the user. This works fine and saves the user with the random name or with their chosen name if a username is entered. My problem is I am not getting any errors returned to the form or a success message when the user is registered. Validation appears to be happening as the user is not being registered if errors are found. Although the only error I see printed is invalid email if entered incorrectly, if the password is missing there is no error returned but the user is not registered.

My code to add the model is as follows. Can anyone point me in the right direction so that the errors are returned. The template is the standard registration form from the craft documentation.

$newUser = new UserModel();
$newUser-&gt;username = $username;
$newUser-&gt;email = $email;
$newUser-&gt;newPassword = $password;

if ($newUser-&gt;validate())
{
    craft()-&gt;users-&gt;saveUser($newUser);
}
else
{
    return $newUser-&gt;getErrors();
}
Most user validation happens in UsersService::saveUser(), so restructure your code to this:



$success = craft()-&gt;users-&gt;saveUser($newUser);

if (!$success)
{
    return $newUser-&gt;getErrors();
}


If this is happening in a controller action, you’ll want to make the UserModel available to the original template, so it can access and display those errors.

$success = craft()-&gt;users-&gt;saveUser($newUser);

if ($success)
{
    // Redirect to whatever URL the 'redirect' param specified
    $this-&gt;redirectToPostedUrl($newUser);
}
else
{
    // Make the UserModel available to the original template
    // so it can access the submitted values and validation errors
    craft()-&gt;urlManager-&gt;setRouteVariables(array(
        'account' =&gt; $newUser
    ));
}