Could you please help to add a new custom field in Magento 2
contact form.
1 Answer
Open your form.phtml
file.
/magento_root/app/design/frontend/VENDER/YOUR_THEME/Magento_Contact/templates/form.phtml
Then add mycustomfield
field to this contact form:
<div class="field mycustomfield required">
<label class="label" for="mycustomfield"><span><?php /* @escapeNotVerified */ echo __('my custom field') ?></span></label>
<div class="control">
<input name="mycustomfield" id="mycustomfield" title="<?php /* @escapeNotVerified */ echo __('my custom field') ?>" value="" class="input-text" type="text" data-validate="{required:true}"/>
</div>
</div>
Add the above field in the form.
Go to MARKETING > Communication > Email Templates
in the Magento Admin section. Click "Add New Template" and from the "Template" dropdown box select "Contact Form" then "Load Template". Under template content you can add your custom field:
Add your new field as per your requirement. it should looks like this:
{{trans "My Custom Field: %mycustomfield" mycustomfield=$data.mycustomfield}}
{{trans "Name: %name" name=$data.name}}
{{trans "Email: %email" email=$data.email}}
{{trans "Phone Number: %telephone" telephone=$data.telephone}}
{{trans "Comment: %comment" comment=$data.comment}}
Enter a new name under "Template Name" to save your new Template and click on "Save Template". Now we need to tell Magento to use this new template for the Contact form.
Go to STORES -> Settings -> Configuration -> General -> Contacts and select "Contacts". Under "Email Options"
,
Select your new template under the "Email Options" -> "Email Template"
dropdown box.
Click on "Save Config".
-
i have tried this solution and working fine but i have trying the get the Attachment file but Attachment file is not showing.But Only showing the file name Please help me. Commented Feb 16, 2020 at 5:08
-
Please check screen-short prnt.sc/r2yo9s , Please help me Commented Feb 16, 2020 at 5:12