3

I'm looking for a way to be able to add a Dropdown (select) to the Contact Page and use it as a Subject later on in the email.

I've tried simply adding a dropdown but it doesn't seem to be working:

this is what I've tried in form.phtml

<div class="field subject required">
    <div class="control">
        <select id="subject" data-validate="{required:true}"/>
            <option value="Subject" disabled>Subject</option>
            <option value="volvo">Volvo</option>
            <option value="volvo">Volvo</option>
            <option value="saab">Saab</option>
            <option value="mercedes">Mercedes</option>
            <option value="audi">Audi</option>
        </select> 
    </div>
</div>

and this is the Email Templates

{{trans "Subject: %subject" subject=$data.subject}}
1

I had the same issue, the dropdown value cannot be passed to email template, but the input type do.

I use js to pass the value to input and make it working. It is not perfect but it is working. would like to know better solution.

in Magento_Contact/templates/form.phtml.

<div class="field enquiry">
<label class="label" for="enquiry"><span><?php echo __('Enquiry type?') ?></span></label>
<div class="control">
    <input name="enquiry" id="enquiry" title="<?php echo __('enquiry') ?>" value="Product Enquiry" class="input-text hide" type="text" />
    <select name="enquiry" id="enquiry_mirror">
        <option value="Product Enquiry" selected>Product Enquiry</option>
        <option value="Track my order">Track my order</option>
        <option value="other">other</option>
    </select>
</div>

<script>
require(['jquery'], function($){

  $(document).ready(function () {
      $('#enquiry_mirror').change(function () {
          $('#enquiry').val($(this).val());
      });
  });

});
</script>

Then in email template

{{trans "Enquiry Type: %enquiry" enquiry=$data.enquiry}}
|improve this answer|||||

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.