2

following other guides, I added in the page form to

/httpdocs/vendor/magento/module-contact/view/frontend/templates/form.phtml

and I added the code

<div class="field selezione required">
 <label class="label" for="subject"><span><?php /* @escapeNotVerified */ echo __('Come hai conosciuto AvaloItalia?') ?></span></label>
 <div class="control">
 <select selectname="selezione" id="selezione" title="<?php /* @escapeNotVerified */ echo __('Come hai conosciuto AvaloItalia?') ?>" data-validate="{required:true}" value="ciao">
 <option value="facebook">Facebook</option>
 <option value="google">Google</option>
 <option value="altro">Altro</option>
 </select> 
 </div>
 </div>

I adjusted the template that I get email but the field is always empty.

{{trans "Name: %name" name=$data.name}}
{{trans "Email: %email" email=$data.email}}
{{trans "Phone Number: %telephone" telephone=$data.telephone}}
{{trans "Come hai conosciuto AvalonItalia?: %selezione" selezione=$data.selezione}}
{{trans "Comment: %comment" comment=$data.comment}}

What am I doing wrong? how can i fix it?

asked Mar 19, 2018 at 17:37
4
  • Could you share what variable you have added in your email template ? Commented Mar 20, 2018 at 4:52
  • I went into Marketing-> Email Templates and I created a new model using the default one, I added the variable {{trans "Come hai conosciuto AvalonItalia?: %selezione" selezione=$data.selezione}} and I used this template as default. I modify question with code Template Email. Commented Mar 20, 2018 at 8:43
  • Don't update the core modules files, you have to override the module-contactthen you update the phtml as you need in a new one ! Commented Mar 21, 2018 at 19:49
  • how can i do this? Commented Mar 21, 2018 at 20:34

1 Answer 1

1

I did this in Magento 2.2.X

1) Put this in your app/design/frontend/[theme-provider]/[theme-name]/Magento_Contact/templates/form.phtml and modify it to your liking, for example add a new select box as follows:

<div class="field region input-box">
 <label for="dropdown"><span><?php /* @escapeNotVerified */ echo __('Region') ?></span></label>
 <select name="dropdown" id="dropdown">
 <option value="selected">select...</option>
 <option name="retail" value="Retail">Retail</option>
 <option name="wholesale" value="Wholesale">Wholesale</option>
 <option name="customerservice" value="CustomerService">Customer Service</option>
 <option name="logistics" value="logistics">Logistics</option>
 <option name="general" value="General">General</option>
 </select>
 </div>

2) Run this code:

php bin/magento setup:upgrade
php bin/magento cache:flush

3) In your dashboard go to > Marketing> Email Templates, you need to create a new template if you don't have one

4) In Load default template choose a template in this case Contact Form and click on the button Load Template.

5) Add a name to the template.

6) In template content Open a space in the code and place this:

<tr>
 <td><b>{{trans "Region"}}</b></td>
 <td>{{var data.dropdown}}</td>
</tr>

7) in your dashboard go to > STORES> Configuration> General Contacts> Email Options> Email Template, choose your new email template and save.

3
  • This returns the option value for me. Is there any way to return the label instead? Commented Apr 15, 2019 at 3:41
  • Thank you man! It worked like a charm! Commented Apr 30, 2020 at 17:30
  • Confirmed: works on 2.4.6.! Commented May 15, 2024 at 21:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.