0

We want to add a country field in the contact form in Magento 1.9 We need country option as drop down. Also, we want to send the selected country in contact mail.

My code

<?php $_countries = Mage::getResourceModel('directory/country_collection')->loadByStore()->toOptionArray(false) ?> 
<?php if (count($_countries) > 0): ?> <select name="billing[country_id]" id="billing:country_id" class="validate-select"> 
<option value="">Please choose a country...</option> 
<?php foreach($_countries as $_country): ?>
<option value="<?php echo $_country['value'] ?>">
<?php echo $_country['label'] ?> 
</option> 
<?php endforeach; ?>
</select> 

Any help me how to send this country field data in contact us mail?

  • We find it's solution. <?php $_countries = Mage::getResourceModel('directory/country_collection')->loadByStore()->toOptionArray(false) ?> <?php if (count($_countries) > 0): ?> <select name="billing[country_id]" id="billing:country_id" class="validate-select"> <option value="">Please choose a country...</option> <?php foreach($_countries as $_country): ?> <option value="<?php echo $_country['value'] ?>"> <?php echo $_country['label'] ?> </option> <?php endforeach; ?> </select> <?php endif; ?> – Anil Jun 15 '19 at 5:49
  • Any help me how to send this country field data in contact us mail ? – Anil Jun 15 '19 at 5:50
  • Anil, did you try my solution ? – Pawan Jun 17 '19 at 18:24
0

If you manage to add extra filed, it will automatically go to add in form.

when you submit form and print data in controller's postAction at:

magento1Root/app/code/core/Mage/Contacts/controllers/IndexController.php

You will get your new filed value Here. You don't need to change/add anything in the above controller, it is just for checking the value you are getting.

As the above controller is sending all value in data to the template, You just need to add:

data.[field_name] in email template.

You can find email template at:

/var/www/html/magento1938/app/locale/en_US/template/email/contact_form.html

You just need to add:

{{var data.[field_name]}}

Hope above will help

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.