Returning errors into templates When working with a custom form that posts to a plugin function - what's the best way to return errors that would be displayed like the forgot password code example below

    {% if errors is defined %}
        &lt;ul class="errors"&gt;
            {% for error in errors %}
                &lt;li&gt;{{ error }}&lt;/li&gt;
            {% endfor %}
        &lt;/ul&gt;
    {% endif %}
I just return the form model object back to the template. Yii has built in validation and error handling within the models themselves. In the example email is the instance of your form's model.

The template:

{% if email is not defined %}
    {% set email = craft.postmaster.email() %}
{% endif %}

{% for error in email.getAllErrors() %}
    &lt;p&gt;{{ error }}&lt;/p&gt;
{% endfor %}

&lt;p&gt;
    &lt;label for="toEmail"&gt;To Email&lt;/label&gt;&lt;br&gt;
    &lt;input type="text" id="toEmail" name="toEmail" value="{{ email.toEmail }}" /&gt;
    {% if email.getError('toEmail') %}
    &lt;label for="toEmail"&gt;{{ email.getError('toEmail') }}&lt;/label&gt;
    {% endif %}
&lt;/p&gt;


The controller:

$model = new Postmaster_EmailFormModel(craft()-&gt;request-&gt;getPost());

if(!$model-&gt;validate())
{ 
    // Prepare a flash error message for the user.
    craft()-&gt;userSession-&gt;setError(Craft::t('The email could not be sent.'));

    craft()-&gt;urlManager-&gt;setRouteVariables(array(
        'email' =&gt; $model
    ));
}
else
{
    $event = new Event($this, array(
        'email' =&gt; $model
    ));

    craft()-&gt;postmaster_forms-&gt;onEmailFormSend($event);

    $this-&gt;redirect(craft()-&gt;request-&gt;getPost('redirect'));
}