Answers.Body: <blockquote>
    <p>I think this:</p>
  
  <pre><code>{% for error in errors %}
      &lt;li&gt;{{ error }}&lt;/li&gt;
  {% endfor %}
  </code></pre>
    
    <p>... is where the error originates.</p>
    
    <p>I memory serves me right, <code>errors</code> is an array like this:</p>
  
  <pre><code>[
      ['fieldHandle' =&gt; ['Something went terribly wrong!', 'Really, two errors in ONE FIELD?']],
      ['orderFieldHandle' =&gt; 'I AM REQUIRED, y\'all!'],
  ];
  </code></pre>
    
    <p>In which case <code>{{ error }}</code> would dictate Twig (and therefore PHP) to
    echo an array (<code>['fieldHandle' =&gt; ['Something went terribly wrong!',
    'Really, two errors in ONE FIELD?']]</code>), resulting in the error you
    mentioned.</p>
    
    <p>You can fix this, by using the following code:</p>
  
  <pre><code>{% for fieldHandle, fieldErrors in errors %}
      &lt;li&gt;{{ fieldHandle }}: {{ fieldErrors |join(', ') }}&lt;/li&gt;
  {% endfor %}
  </code></pre>
  </blockquote>
  
  <p>My original answer was not what caused the error (so, apparently, errors was not what I thought it was).</p>
  
  <p>This type of error is caused by an array being echoed by PHP, and not a string. In this case, the cause of the problem is {{ message.message ?? '' }}, which turned into an array because it contains multiple field values.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-12T13:27:32.043Z
Answers.Text: Not exactly... One field can have several different errors thus `['fieldHandle' => ['Something went terribly wrong!' , 'an something else too']]`
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-12T13:28:20.630Z
Answers.Text: Will edit that in, but it's still the reason for the error ;)
Answers.UserDisplayName: Paul
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-12T13:28:50.750Z
Answers.Text: I never said something else :P
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-13T16:01:45.457Z
Answers.Text: Thanks so much! Forgive my limited understanding of the issue, but could you suggest a way to fix the code?
Answers.UserDisplayName: Clay Kilby
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-13T16:07:22.260Z
Answers.Text: Added a suggestion to solve the error :)
Answers.UserDisplayName: Paul
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-13T16:47:23.083Z
Answers.Text: Thanks! Just tried that and still threw the error, but then I noticed that I had not added .body to the text area. Changing {{ message.message ?? '' }} to {{ message.message.body ?? '' }} resolved the php error. But with your new code I found it outputting errors with a number prefix, "0: Your Email cannot be blank." instead of "Your Email cannot be blank." I swapped back in the original {% for error in errors %} <li>{{ error }}</li> {% endfor %} code and all is good now!
Answers.UserDisplayName: Clay Kilby
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-13T16:56:03.760Z
Answers.Text: Ah! Then that's where the error came from. Message.message turned into an array, the minute you decided to put more than one field into `message`. Hard one to spot, if you didn't build it yourself :) I will edit my answer for other people running into this error.
Answers.UserDisplayName: Paul
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-12T13:24:37.827Z
Answers.LastActivityDate: 2018-04-13T16:59:03.797Z
Answers.LastEditDate: 2018-04-13T16:59:03.797Z
Answers.UserDisplayName: Paul
Body: <p>I'm having trouble with additional message fields in my Craft Contact Form using Craft 3 and the Pixel &amp; Tonic Contact Form plugin.</p>
  
  <p>I've added two additional fields by splitting up the message field as described in the plugin documentation. If all the fields are filled in, everything goes smoothly. But if the form is submitted with any blank required fields, I get a PHP error "Array to string conversion." Live example at <a href="http://striveforfive.creativeforthepeople.org/contact" rel="nofollow noreferrer">http://striveforfive.creativeforthepeople.org/contact</a>.</p>
  
  <p>EDIT: The code is:</p>
  
  <pre><code>    {% if entry.formCopy|length %}{{ entry.formCopy }}{% endif %}
      {% 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 class="contact-form" method="post" action="" accept-charset="UTF-8"&gt;
          &lt;div class="form-group"&gt;
              {{ csrfInput() }}
              &lt;input type="hidden" class="form-control" name="action" value="contact-form/send"&gt;
              {{ redirectInput('contact-ty') }}
  
              &lt;input id="from-name" class="form-control" type="text" name="fromName" value="{{ message.fromName ?? '' }}" placeholder="your name"&gt;
              {{ message is defined and message ? errorList(message.getErrors('fromName')) }}
  
              &lt;input id="from-email" class="form-control" type="email" name="fromEmail" value="{{ message.fromEmail ?? '' }}" placeholder="your email"&gt;
              {{ message is defined and message ? errorList(message.getErrors('fromEmail')) }}
  
              &lt;input id="affiliation" class="form-control" type="text" name="message[Affiliation]" value="" placeholder="your school / organization / home locations"&gt;
  
              &lt;select id="position" class="form-control" type="text" name="message[Position]" value=""&gt;
                  &lt;option value="" selected disabled&gt;your position&lt;/option&gt;
                  &lt;option&gt;Educator / Care Giver&lt;/option&gt;
                  &lt;option&gt;Family Child Care Provider&lt;/option&gt;
                  &lt;option&gt;Center Director&lt;/option&gt;
                  &lt;option&gt;Student Teacher&lt;/option&gt;
                  &lt;option&gt;Other&lt;/option&gt;
              &lt;/select&gt;
  
              &lt;textarea rows="5" cols="40" id="message" class="form-control" name="message[body]" placeholder="your message"&gt;{{ message.message ?? '' }}&lt;/textarea&gt;
              {{ message is defined and message ? errorList(message.getErrors('message')) }}
  
              &lt;input id="bluebeard" name="bluebeard" type="text"&gt;
  
              &lt;input id="contact-submit" type="submit" class="btn btn-outline-primary" value="Send"&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>All help is appreciated!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-11T13:52:20.270Z
Comments.Text: Can you share the contact form code you're using on the backend?
Comments.UserDisplayName: Jalen Davenport
Tags: <craft3><plugin-contactform>
Title: PHP Exception for errors on Craft Contact Form with additional fields
ThreadText: # PHP Exception for errors on Craft Contact Form with additional fields
  
  (Asked by: username_0 on 2018-04-10)
  
  I'm having trouble with additional message fields in my Craft Contact Form using Craft 3 and the Pixel & Tonic Contact Form plugin.
  
  I've added two additional fields by splitting up the message field as described in the plugin documentation. If all the fields are filled in, everything goes smoothly. But if the form is submitted with any blank required fields, I get a PHP error "Array to string conversion." Live example at <http://striveforfive.creativeforthepeople.org/contact>.
  
  EDIT: The code is:
  
  ```
      {% if entry.formCopy|length %}{{ entry.formCopy }}{% endif %}
      {% macro errorList(errors) %}
          {% if errors %}
              <ul class="errors">
                  {% for error in errors %}
                      <li>{{ error }}</li>
                  {% endfor %}
              </ul>
          {% endif %}
      {% endmacro %}
  
      {% from _self import errorList %}
  
      <form class="contact-form" method="post" action="" accept-charset="UTF-8">
          <div class="form-group">
              {{ csrfInput() }}
              <input type="hidden" class="form-control" name="action" value="contact-form/send">
              {{ redirectInput('contact-ty') }}
  
              <input id="from-name" class="form-control" type="text" name="fromName" value="{{ message.fromName ?? '' }}" placeholder="your name">
              {{ message is defined and message ? errorList(message.getErrors('fromName')) }}
  
              <input id="from-email" class="form-control" type="email" name="fromEmail" value="{{ message.fromEmail ?? '' }}" placeholder="your email">
              {{ message is defined and message ? errorList(message.getErrors('fromEmail')) }}
  
              <input id="affiliation" class="form-control" type="text" name="message[Affiliation]" value="" placeholder="your school / organization / home locations">
  
              <select id="position" class="form-control" type="text" name="message[Position]" value="">
                  <option value="" selected disabled>your position</option>
                  <option>Educator / Care Giver</option>
                  <option>Family Child Care Provider</option>
                  <option>Center Director</option>
                  <option>Student Teacher</option>
                  <option>Other</option>
              </select>
  
              <textarea rows="5" cols="40" id="message" class="form-control" name="message[body]" placeholder="your message">{{ message.message ?? '' }}</textarea>
              {{ message is defined and message ? errorList(message.getErrors('message')) }}
  
              <input id="bluebeard" name="bluebeard" type="text">
  
              <input id="contact-submit" type="submit" class="btn btn-outline-primary" value="Send">
          </div>
      </form>
  
  ```
  
  All help is appreciated!
  
  **Tags:** craft3, plugin-contactform
  
  > **Comments:**
  > **username_1**: Can you share the contact form code you're using on the backend?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-04-12. Score: 1
  
  > I think this:
  >
  > ```
  > {% for error in errors %}
  >     <li>{{ error }}</li>
  > {% endfor %}
  >
  > ```
  >
  > ... is where the error originates.
  >
  > I memory serves me right, `errors` is an array like this:
  >
  > ```
  > [
  >     ['fieldHandle' => ['Something went terribly wrong!', 'Really, two errors in ONE FIELD?']],
  >     ['orderFieldHandle' => 'I AM REQUIRED, y\'all!'],
  > ];
  >
  > ```
  >
  > In which case `{{ error }}` would dictate Twig (and therefore PHP) to
  > echo an array (`['fieldHandle' => ['Something went terribly wrong!',
  > 'Really, two errors in ONE FIELD?']]`), resulting in the error you
  > mentioned.
  >
  > You can fix this, by using the following code:
  >
  > ```
  > {% for fieldHandle, fieldErrors in errors %}
  >     <li>{{ fieldHandle }}: {{ fieldErrors |join(', ') }}</li>
  > {% endfor %}
  >
  > ```
  
  My original answer was not what caused the error (so, apparently, errors was not what I thought it was).
  
  This type of error is caused by an array being echoed by PHP, and not a string. In this case, the cause of the problem is {{ message.message ?? '' }}, which turned into an array because it contains multiple field values.
  
  > **Comments:**
  > **username_3**: Not exactly... One field can have several different errors thus `['fieldHandle' => ['Something went terribly wrong!' , 'an something else too']]`  
  > **username_2**: Will edit that in, but it's still the reason for the error ;)  
  > **username_3**: I never said something else :P  
  > **username_0**: Thanks so much! Forgive my limited understanding of the issue, but could you suggest a way to fix the code?  
  > **username_2**: Added a suggestion to solve the error :)  
  > **username_0**: Thanks! Just tried that and still threw the error, but then I noticed that I had not added .body to the text area. Changing {{ message.message ?? '' }} to {{ message.message.body ?? '' }} resolved the php error. But with your new code I found it outputting errors with a number prefix, "0: Your Email cannot be blank." instead of "Your Email cannot be blank." I swapped back in the original {% for error in errors %} <li>{{ error }}</li> {% endfor %} code and all is good now!  
  > **username_2**: Ah! Then that's where the error came from. Message.message turned into an array, the minute you decided to put more than one field into `message`. Hard one to spot, if you didn't build it yourself :) I will edit my answer for other people running into this error.  
  
  ---
  
  