0

If I have a checkbox on the contact form how do I pull these values into the email template.

My form looks like

<li>
    <label for="telephone">Contact Method</label>
    <div class="input-box">
       <input type="checkbox" name="contact_method[]" value="Telephone"> Telephone<br>
       <input type="checkbox" name="contact_method[]" value="Email"> Email<br>
    </div>
 </li>

However if I do

Contact Method: {{var data.contact_method}}

The value comes out as array

  • Did you try changing the name to contact_method instead of contact_method[] ? – Raphael at Digital Pianism Feb 22 '16 at 13:15
  • Yes I tried {{var data.contact_method[]}} and {{var data.contact_method[0]}} but both come out blank – Goose84 Feb 22 '16 at 13:18
  • In your form "<input type="checkbox" name="contact_method[]" value="Telephone"> Telephone<br>" remove the [] from contact_method – Klettseb Feb 22 '16 at 13:19
  • If I remove the [] then only 1 option can be selected – Goose84 Feb 22 '16 at 13:20
  • I didn't notice you were using checkboxes. You should not be using the same name in case of checkboxes, try using two different names and then use 2 lines in your email template. – Raphael at Digital Pianism Feb 22 '16 at 13:22
1

Magento doesn't allow to use array in email variable.So change checkbox html as below.

<input type="checkbox" name="contact_method_tel" value="Telephone"> Telephone<br>
<input type="checkbox" name="contact_method_email" value="Email"> Email<br>

Now use depend condition (can also use if/else) in email template based on below checkbox selection as below.

{{depend data.contact_method_tel}}
    {{var data.contact_method_tel}} //show telephone if checked
{{/depend}}
{{depend data.contact_method_email}}
    {{var data.contact_method_email}} //show email if checked
{{/depend}}

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.