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…

<input name="fromName" id="fromName" value="{% if message is defined %}{{ message.fromName }}{% endif %}" type="text">

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

<input name="message[Phone]" id="phone" type="text" value="">

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 %}
    <input id={{ course.slug }}" name="message[Course]" type="radio" value="{{ course }}"
         {% if message is defined and message.message[Course] == course %}
         {% endif%}>
{% 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?

1 Answer 1


From the changelog:


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]


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.