Contact Form plugin - Error loading 404 Pages So I have a contact form in my layout (just using the contact form plugin from the Craft guys) and on 404 pages I'm getting the following:


  Impossible to invoke a method ("getErrors") on a string variable ("") in "_layout"


What's the best way around that and to still get the contact form to show up on an 404 page?

Many thanks in advance!

Template code is in the footer of _layout.html and looks like this:

&lt;!-- unrelated stuff here... --&gt;

&lt;!-- CONTACT --&gt;

    {% set asset = globalContact.contactBackground.first() %}
    &lt;section id="contact" class="strip contact" style="background-image: url({{ asset.url }});" data-stellar-background-ratio="0.2" data-stellar-responsive="true" data-stellar-horizontal-offset="0"&gt;
        &lt;div class="overlay"&gt;&lt;/div&gt;
        &lt;div class="heading"&gt;
            &lt;h1&gt;
                &lt;span&gt;{{ globalContact.contactPreHeader }}&lt;/span&gt;&lt;br /&gt;
                {{ globalContact.contactHeader }}
            &lt;/h1&gt;
        &lt;/div&gt;
        &lt;div class="inner"&gt;
            {% 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 %}

            {% from _self import errorList %}
            &lt;form method="post" action="" class="contact-form" accept-charset="UTF-8"&gt;
                {{ getCsrfInput() }}
                &lt;input type="hidden" name="action" value="contactForm/sendMessage"&gt;
                &lt;input type="hidden" name="redirect" value="thanks"&gt;

                &lt;div class="contact-name"&gt;
                    &lt;input type="text" id="fromName" name="fromName" placeholder="Name" /&gt;
                    {% if message is defined %}{{ errorList(message.getErrors('fromName')) }}{% endif %}
                &lt;/div&gt;
                &lt;div class="contact-email"&gt;
                    &lt;input type="text" id="fromEmail" name="fromEmail" placeholder="Email" /&gt;
                    {% if message is defined %}{{ errorList(message.getErrors('fromEmail')) }}{% endif %}
                &lt;/div&gt;
                &lt;div class="contact-phone"&gt;
                    &lt;input type="text" id="phone" name="message[Phone]" placeholder="Phone" /&gt;
                &lt;/div&gt;
                &lt;div class="contact-message"&gt;
                    &lt;textarea rows="8" cols="40" id="message" name="message[body]" placeholder="Message"&gt;{% if message is defined %}{{ message.message }}{% endif %}&lt;/textarea&gt;
                    {% if message is defined %}{{ errorList(message.getErrors('message')) }}{% endif %}
                &lt;/div&gt;
                &lt;input id="shewbotsshew" name="shewbotsshew" type="text"&gt;
                &lt;div class="contact-submit"&gt;
                    &lt;input type="submit" value="Submit" /&gt;
                &lt;/div&gt;
            &lt;/form&gt;
        &lt;/div&gt;
    &lt;/section&gt;

&lt;!-- unrelated stuff here... --&gt;
Anywhere you've currently got something that looks like this:

{% if message is defined %}{{ errorList(message.getErrors('fromEmail')) }}{% endif %}


Try changing that to:

{{ message is defined and message ? errorList(message.getErrors('fromEmail')) }}


And you'll want to do that for the other attributes, too ('fromName', etc.).