1

Cannot for the life of me get checkbox values to display in a HTML email template using the Contact Form extensions plugin.

Form snippet:

<input type="hidden" name="message[type]" value="">
<p><input type="checkbox" class="styled-checkbox" name="message[type][]" id="New" value="New">
<label for="New">New</label></p>
<p><input type="checkbox" class="styled-checkbox" name="message[type][]" id="Used" value="Used">
<label for="Used">Used</label></p>

And the email template snippet:

{% if submission.message['type'] %}
<p style="font-size: 16px; line-height: 1.625; color: #51545E; margin: .4em 0 1.1875em;">Type of Quote: {{ submission.message['type'] }}</p>
{% endif %}

Does anyone have a clue about this? I have tried many variations, the above is just one of them. Pulling my hair out ;)

TIA!

1

You're pretty close. In your input you have name="message[type][]". The little [] at the end there means means the data will be stored in an array, something like:

submission: {
  message: {
    type: ['New', 'Used']
  }
}

You have two options here:

Option one

You can change your inputs to be name="message[type]" instead of [type][]. This should result in a data structure more like you're expecting

submission: {
  message: {
    type: 'New'
  }
}

Then your conditional check can be kind of like you have it, but this won't allow multiple values (not sure if you want those or not).

Option Two

Update your conditional check and output to properly output the array values. This would mean something more like:

{% for type in submission.message.type %}
  <p style="font-size: 16px; line-height: 1.625; color: #51545E; margin: .4em 0 1.1875em;">
    Type of Quote: {{ submission.message.type }}
  </p>
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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