Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-13T17:34:57.783Z
Answers.Text: FWIW, updated the example code here to reflect the change, too: https://github.com/pixelandtonic/ContactForm#usage
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-13T16:42:12.633Z
Answers.LastActivityDate: 2014-10-13T16:42:12.633Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-13T16:27:09.537Z
Comments.Text: 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?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-13T16:36:47.667Z
Comments.Text: Done - hope that helps.
Comments.UserDisplayName: Jeremy Bise
Tags: <404-page><plugin-contactform>
Title: Contact Form plugin - Error loading 404 Pages
ThreadText: # 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:
  
  ```
  <!-- unrelated stuff here... -->
  
  <!-- CONTACT -->
  
      {% set asset = globalContact.contactBackground.first() %}
      <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">
          <div class="overlay"></div>
          <div class="heading">
              <h1>
                  <span>{{ globalContact.contactPreHeader }}</span><br />
                  {{ globalContact.contactHeader }}
              </h1>
          </div>
          <div class="inner">
              {% macro errorList(errors) %}
                  {% if errors %}
                      <ul class="errors">
                          {% for error in errors %}
                              <li>{{ error }}</li>
                          {% endfor %}
                      </ul>
                  {% endif %}
              {% endmacro %}
  
              {% from _self import errorList %}
              <form method="post" action="" class="contact-form" accept-charset="UTF-8">
                  {{ getCsrfInput() }}
                  <input type="hidden" name="action" value="contactForm/sendMessage">
                  <input type="hidden" name="redirect" value="thanks">
  
                  <div class="contact-name">
                      <input type="text" id="fromName" name="fromName" placeholder="Name" />
                      {% if message is defined %}{{ errorList(message.getErrors('fromName')) }}{% endif %}
                  </div>
                  <div class="contact-email">
                      <input type="text" id="fromEmail" name="fromEmail" placeholder="Email" />
                      {% if message is defined %}{{ errorList(message.getErrors('fromEmail')) }}{% endif %}
                  </div>
                  <div class="contact-phone">
                      <input type="text" id="phone" name="message[Phone]" placeholder="Phone" />
                  </div>
                  <div class="contact-message">
                      <textarea rows="8" cols="40" id="message" name="message[body]" placeholder="Message">{% if message is defined %}{{ message.message }}{% endif %}</textarea>
                      {% if message is defined %}{{ errorList(message.getErrors('message')) }}{% endif %}
                  </div>
                  <input id="shewbotsshew" name="shewbotsshew" type="text">
                  <div class="contact-submit">
                      <input type="submit" value="Submit" />
                  </div>
              </form>
          </div>
      </section>
  
  <!-- unrelated stuff here... -->
  
  ```
  
  **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  
  
  ---
  
  