<p>It looks like you're not returning the user model back to the template.</p>

<p>You need something like this in your controller.</p>

<pre><code>craft()-&gt;urlManager-&gt;setRouteVariables(array(
    'account' =&gt; $user
));
</code></pre>

CC BY-SA 3.0
2016-11-20T12:08:13.500Z
2016-11-20T12:08:13.500Z
Jamie Pittock
<p>I'm building a custom registration process in which a set of entries <strong>and</strong> a user are created at the same time.</p>

<p><strong>Currently I'm not able to pass back my errors in my controller into the front-end template.</strong></p>

<p>(The following code <strong><em>should</em></strong> error out on purpose to test this functionality)</p>

<p><strong>In my plugin controller:</strong></p>

<pre><code>$user = new UserModel;
$wasSaved = craft()-&gt;users-&gt;saveUser($user);

if ($wasSaved) {
     $was_assigned = craft()-&gt;userGroups-&gt;assignUserToGroups($user-&gt;id, array(1));
} else {
     $user-&gt;addErrors($user-&gt;getErrors());
     var_export($user-&gt;getErrors());
     return false;
}
</code></pre>

<p><strong>In my template</strong></p>

<pre><code>{% macro errorList(errors) %}
{% if errors %}
  &lt;ul class="errors"&gt;
     {% for error in errors %}
         &lt;li&gt;{{ error }}&lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
{% endif %}
{% endmacro %}

{% if account.getErrors is defined %}
    {{ _self.errorList(account.getErrors()) }}
{% endif %}
</code></pre>

<p>With the <code>var_export($user-&gt;getErrors());</code> in my controller, I can see the errors at the top of the page:</p>

<pre><code>array ( 'username' =&gt; array ( 0 =&gt; 'Username cannot be blank.', 1 =&gt; 'Username cannot be blank.', ),
'email' =&gt; array ( 0 =&gt; 'Email cannot be blank.', 1 =&gt; 'Email cannot be blank.', ), )
</code></pre>

<p>but these errors are not making it back into the actual template.</p>

<p>Any ideas?</p>

<plugin-development><users><registration>
Custom registration User validation
# Custom registration User validation

(Asked by: username_0 on 2016-11-20)

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 %}
  
     {% for error in errors %}
         {{ error }}
      {% endfor %}
  
{% 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?

**Tags:** plugin-development, users, registration

---

## 1 answers

### Answer by username_1 on 2016-11-20. Score: 3 | Accepted answer

It looks like you're not returning the user model back to the template.
You need something like this in your controller.
craft()->urlManager->setRouteVariables(array(
    'account' => $user
));


---

