I'm building a custom registration process in which a set of entries and a user are created at the same time.
Currently I'm not able to pass back my errors in my controller into the front-end template.
(The following code should error out on purpose to test this functionality)
In my plugin controller:
$user = new UserModel;
$wasSaved = craft()->users->saveUser($user);
if ($wasSaved) {
$was_assigned = craft()->userGroups->assignUserToGroups($user->id, array(1));
} else {
$user->addErrors($user->getErrors());
var_export($user->getErrors());
return false;
}
In my template
{% macro errorList(errors) %}
{% if errors %}
<ul class="errors">
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
{% if account.getErrors is defined %}
{{ _self.errorList(account.getErrors()) }}
{% endif %}
With the var_export($user->getErrors());
in my controller, I can see the errors at the top of the page:
array ( 'username' => array ( 0 => 'Username cannot be blank.', 1 => 'Username cannot be blank.', ),
'email' => array ( 0 => 'Email cannot be blank.', 1 => 'Email cannot be blank.', ), )
but these errors are not making it back into the actual template.
Any ideas?