<p>From the changelog:</p>

<blockquote>
  <p>1.7.0</p>
  
  <p>Added the ability to access individual message fields values via <code>message.messageFields</code> when a validation error occurred. For example, the value of the input <code>message[Phone]</code> can now be accessed via <code>message.messageFields['Phone']</code>.</p>
</blockquote>

<p>So I think you should be using <code>message.messageFields[Course]</code> rather than <code>message.message[Course]</code></p>

CC BY-SA 3.0
2017-03-21T00:53:00.110Z
2017-03-21T00:53:00.110Z
Sarah
<p>I'm using <a href="https://github.com/pixelandtonic/ContactForm/blob/master/README.md#adding-additional-fields" rel="nofollow noreferrer">additional fields</a> on my contact form. I want to re-populate the additional fields if/when the form fails validation, but it's not working so far.</p>

<p>To re-populate a <strong>standard</strong> field, the code uses an attribute of message using dot syntax…</p>

<pre><code>&lt;input name="fromName" id="fromName" value="{% if message is defined %}{{ message.fromName }}{% endif %}" type="text"&gt;
</code></pre>

<p>But for <strong>additional fields</strong> the value is stored as an attribute of message.message using <a href="http://twig.sensiolabs.org/doc/2.x/templates.html#variables" rel="nofollow noreferrer">the subscript syntax</a> (the use of square brackets below)…</p>

<pre><code>&lt;input name="message[Phone]" id="phone" type="text" value=""&gt;
</code></pre>

<p>I'm having trouble accessing the substring value on message.message. In my specific example, I have several radio buttons that need their selections remembered in case anything goes wrong. Here's what I expected to work…</p>

<pre><code>{% for course in courses %}
    &lt;input id={{ course.slug }}" name="message[Course]" type="radio" value="{{ course }}"
         {% if message is defined and message.message[Course] == course %}
             checked="checked"
         {% endif%}&gt;
{% endfor %}
</code></pre>

<p>However, this code outputs the template error:</p>

<pre><code>Variable "Course" does not exist.
</code></pre>

<p>How can I re-populate the additional fields for the contact form plugin?</p>

<plugin-contactform>
Re-populate additional fields on Contact Form on failure of form validation
# Re-populate additional fields on Contact Form on failure of form validation

(Asked by: username_0 on 2017-03-21)

I'm using additional fields on my contact form. I want to re-populate the additional fields if/when the form fails validation, but it's not working so far.
To re-populate a standard field, the code uses an attribute of message using dot syntax…


But for additional fields the value is stored as an attribute of message.message using the subscript syntax (the use of square brackets below)…


I'm having trouble accessing the substring value on message.message. In my specific example, I have several radio buttons that need their selections remembered in case anything goes wrong. Here's what I expected to work…
{% for course in courses %}
    
{% endfor %}

However, this code outputs the template error:
Variable "Course" does not exist.

How can I re-populate the additional fields for the contact form plugin?

**Tags:** plugin-contactform


---

## 1 answers

### Answer by username_1 on 2017-03-21. Score: 3 | Accepted answer

From the changelog:

> 1.7.0
>
> Added the ability to access individual message fields values via `message.messageFields` when a validation error occurred. For example, the value of the input `message[Phone]` can now be accessed via `message.messageFields['Phone']`.

So I think you should be using `message.messageFields[Course]` rather than `message.message[Course]`


---

