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?

3
  • 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, 2019 at 5:49
  • Any help me how to send this country field data in contact us mail ?
    – Anil
    Jun 15, 2019 at 5:50
  • Anil, did you try my solution ?
    – Pawan
    Jun 17, 2019 at 18:24

1 Answer 1

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.