<p>Anywhere you've currently got something that looks like this:</p>

<pre><code>{% if message is defined %}{{ errorList(message.getErrors('fromEmail')) }}{% endif %}
</code></pre>

<p>Try changing that to:</p>

<pre><code>{{ message is defined and message ? errorList(message.getErrors('fromEmail')) }}
</code></pre>

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

CC BY-SA 3.0
2014-10-13T17:34:57.783Z
FWIW, updated the example code here to reflect the change, too: https://github.com/pixelandtonic/ContactForm#usage
Brad Bell
CC BY-SA 3.0
2014-10-13T16:42:12.633Z
2014-10-13T16:42:12.633Z
Brad Bell
<p>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:</p>

<blockquote>
  <p>Impossible to invoke a method ("getErrors") on a string variable ("") in "_layout"</p>
</blockquote>

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

<p>Many thanks in advance!</p>

<p>Template code is in the footer of _layout.html and looks like this:</p>

<pre><code>&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;
</code></pre>

CC BY-SA 3.0
2014-10-13T16:27:09.537Z
I'm guessing you've got the contact form code in a footer or header include on your site?  Can you update the question with the template code?
Brad Bell
CC BY-SA 3.0
2014-10-13T16:36:47.667Z
Done - hope that helps.
Jeremy Bise
<404-page><plugin-contactform>
Contact Form plugin - Error loading 404 Pages
# Contact Form plugin - Error loading 404 Pages

(Asked by: username_0 on 2014-10-13)

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:




    {% set asset = globalContact.contactBackground.first() %}
    
        
        
            
                {{ globalContact.contactPreHeader }}
                {{ globalContact.contactHeader }}
            
        
        
            {% macro errorList(errors) %}
                {% if errors %}
                    
                        {% for error in errors %}
                            {{ error }}
                        {% endfor %}
                    
                {% endif %}
            {% endmacro %}

            {% from _self import errorList %}
            
                {{ getCsrfInput() }}
                
                

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

**Tags:** 404-page, plugin-contactform

> **Comments:**
> **username_1**: I'm guessing you've got the contact form code in a footer or header include on your site?  Can you update the question with the template code?  
> **username_0**: Done - hope that helps.  

---

## 1 answers

### Answer by username_1 on 2014-10-13. Score: 4 | Accepted answer

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.).

> **Comments:**
> **username_1**: FWIW, updated the example code here to reflect the change, too: https://github.com/pixelandtonic/ContactForm#usage  

---

