put country dropdown in phtml file in magento2Magento 2 : How can I upload files of dynamically added file...

Is layered encryption more secure than long passwords?

How bad is a Computer Science course that doesn't teach Design Patterns?

How many copper coins fit inside a cubic foot?

put country dropdown in phtml file in magento2

Could Comets or Meteors be used to Combat Global Warming?

How does the income of your target audience matter for logo design?

How can a kingdom keep the secret of a missing monarch from the public?

Why is ra lower than re while la is higher than le?

Where can I educate myself on D&D universe lore, specifically on vampires and supernatural monsters?

I hate taking lectures, can I still survive in academia?

Why do some musicians make such weird faces when they play?

Found a major flaw in paper from home university – to which I would like to return

Is there a way to draw a level tree?

Is it common to refer to someone as "Prof. Dr. [LastName]"?

Coworker is trying to get me to sign his petition to run for office. How to decline politely?

How to know if I am a 'Real Developer'

Fired for using Stack Exchange. What did I do wrong?

Face Value of SOFR futures

What caused Doctor Strange to repent of his selfishness and become Earth's protector?

Why Third 'Reich'? Why is 'reich' not translated when 'third' is? What is the English synonym of reich?

Discouraging missile alpha strikes

Short story where Earth is given a racist governor who likes species of a certain color

Integral check. Is partial fractions the only way?

The Longest Chess Game



put country dropdown in phtml file in magento2


Magento 2 : How can I upload files of dynamically added file input fields in the adminMagento 2 Add new field to Magento_User admin formHow to add a custom field to the frontend customer registration form in magento 2?UI component hidden input on checkout addressHow to create a custom form for sending email with file Attachment in magento 2Magento 2 : How to change UI field(s) dynamicallyMagento 2, address->getRegion() return object instead of stringhow to add category using factory method not object managerProblem when validating city field when registering new address at checkout M2Magento 2. Make Address Fields Not Required at Customer Registration













2















sayhello.phtml



<!DOCTYPE html>
<html>
<head>
<h2>Wholesale and Dealer Inquiries Form</h2>
</head>
<body>
<table align="center">
<form action="<?php echo $block-
>getBaseUrl().'wholesaleapplication/index/post/';?>" method="post">
<tr>
<td><label> Business Name </label></td>
<td> <input type="text" name="name"></td>
</tr>
<tr>
<td><label> Contact Name </label></td>
<td><input type="text" name="cname"></td>
</tr>
<tr>
<td> <label> E-mail </label></td>
<td><input type="email" name="email"></td>
</tr>
<tr>
<td> <label> Address </label></td>
<td><input type="text" name="address">
<label> Street Address </label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="address2">
<label> Street Address line 2</label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="city">
<label>city</label></td>
<td><input type="text" name="state">
<label>state/province</label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="zipcode">
<label>postal zip/code</label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="areacode">
<label>area code</label></td>
<td><input type="text" name="phonenumber">
<label>phone number</label></td>
</tr>
<tr>
<td> <label class="form-label form-label-left form-label-auto" id="label_9" for="input_9"> Website </label></td>
<td><input type="text" name="website"></td>
</tr>
<tr>
<td> <label> Reseller Permit </label></td>
<td><input type="text" name="reseller"></td>
</tr>
<tr>
<td> <label> Description of Business </label></td>
<td><textarea name="description" ></textarea></td>
</tr>
<tr>
<td> <label> Additional Questions and Comments </label></td>
<td><textarea name="additional" ></textarea></td>
</tr>
<tr>
<td> <label> click to edit </label></td>
<td><input type="file"></td>
</tr>
<tr>
<td><button type="submit" name="submit">
Submit
</button></td>
</tr>

</form>





country dropdowncode



<?php $_countries = 
Mage::getResourceModel('directory/country_collection')
loadData()
toOptionArray(false) ?>
<?php if (count($_countries) > 0): ?>
<select name="country" id="country">
<option value="">-- Please Select --</option>
<?php foreach($_countries as $_country): ?>
<option value="<?php echo $_country['value'] ?>">
<?php echo $_country['label'] ?>
</option>
<?php endforeach; ?>
</select>
<?php endif; ?>


i want drop down near zip code in phtml file where to keep this country code?










share|improve this question























  • you have tried Magento 1 code>

    – Amit Bera
    3 hours ago











  • can you please share me magento2 code

    – Ashish Ramchandani
    3 hours ago
















2















sayhello.phtml



<!DOCTYPE html>
<html>
<head>
<h2>Wholesale and Dealer Inquiries Form</h2>
</head>
<body>
<table align="center">
<form action="<?php echo $block-
>getBaseUrl().'wholesaleapplication/index/post/';?>" method="post">
<tr>
<td><label> Business Name </label></td>
<td> <input type="text" name="name"></td>
</tr>
<tr>
<td><label> Contact Name </label></td>
<td><input type="text" name="cname"></td>
</tr>
<tr>
<td> <label> E-mail </label></td>
<td><input type="email" name="email"></td>
</tr>
<tr>
<td> <label> Address </label></td>
<td><input type="text" name="address">
<label> Street Address </label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="address2">
<label> Street Address line 2</label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="city">
<label>city</label></td>
<td><input type="text" name="state">
<label>state/province</label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="zipcode">
<label>postal zip/code</label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="areacode">
<label>area code</label></td>
<td><input type="text" name="phonenumber">
<label>phone number</label></td>
</tr>
<tr>
<td> <label class="form-label form-label-left form-label-auto" id="label_9" for="input_9"> Website </label></td>
<td><input type="text" name="website"></td>
</tr>
<tr>
<td> <label> Reseller Permit </label></td>
<td><input type="text" name="reseller"></td>
</tr>
<tr>
<td> <label> Description of Business </label></td>
<td><textarea name="description" ></textarea></td>
</tr>
<tr>
<td> <label> Additional Questions and Comments </label></td>
<td><textarea name="additional" ></textarea></td>
</tr>
<tr>
<td> <label> click to edit </label></td>
<td><input type="file"></td>
</tr>
<tr>
<td><button type="submit" name="submit">
Submit
</button></td>
</tr>

</form>





country dropdowncode



<?php $_countries = 
Mage::getResourceModel('directory/country_collection')
loadData()
toOptionArray(false) ?>
<?php if (count($_countries) > 0): ?>
<select name="country" id="country">
<option value="">-- Please Select --</option>
<?php foreach($_countries as $_country): ?>
<option value="<?php echo $_country['value'] ?>">
<?php echo $_country['label'] ?>
</option>
<?php endforeach; ?>
</select>
<?php endif; ?>


i want drop down near zip code in phtml file where to keep this country code?










share|improve this question























  • you have tried Magento 1 code>

    – Amit Bera
    3 hours ago











  • can you please share me magento2 code

    – Ashish Ramchandani
    3 hours ago














2












2








2








sayhello.phtml



<!DOCTYPE html>
<html>
<head>
<h2>Wholesale and Dealer Inquiries Form</h2>
</head>
<body>
<table align="center">
<form action="<?php echo $block-
>getBaseUrl().'wholesaleapplication/index/post/';?>" method="post">
<tr>
<td><label> Business Name </label></td>
<td> <input type="text" name="name"></td>
</tr>
<tr>
<td><label> Contact Name </label></td>
<td><input type="text" name="cname"></td>
</tr>
<tr>
<td> <label> E-mail </label></td>
<td><input type="email" name="email"></td>
</tr>
<tr>
<td> <label> Address </label></td>
<td><input type="text" name="address">
<label> Street Address </label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="address2">
<label> Street Address line 2</label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="city">
<label>city</label></td>
<td><input type="text" name="state">
<label>state/province</label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="zipcode">
<label>postal zip/code</label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="areacode">
<label>area code</label></td>
<td><input type="text" name="phonenumber">
<label>phone number</label></td>
</tr>
<tr>
<td> <label class="form-label form-label-left form-label-auto" id="label_9" for="input_9"> Website </label></td>
<td><input type="text" name="website"></td>
</tr>
<tr>
<td> <label> Reseller Permit </label></td>
<td><input type="text" name="reseller"></td>
</tr>
<tr>
<td> <label> Description of Business </label></td>
<td><textarea name="description" ></textarea></td>
</tr>
<tr>
<td> <label> Additional Questions and Comments </label></td>
<td><textarea name="additional" ></textarea></td>
</tr>
<tr>
<td> <label> click to edit </label></td>
<td><input type="file"></td>
</tr>
<tr>
<td><button type="submit" name="submit">
Submit
</button></td>
</tr>

</form>





country dropdowncode



<?php $_countries = 
Mage::getResourceModel('directory/country_collection')
loadData()
toOptionArray(false) ?>
<?php if (count($_countries) > 0): ?>
<select name="country" id="country">
<option value="">-- Please Select --</option>
<?php foreach($_countries as $_country): ?>
<option value="<?php echo $_country['value'] ?>">
<?php echo $_country['label'] ?>
</option>
<?php endforeach; ?>
</select>
<?php endif; ?>


i want drop down near zip code in phtml file where to keep this country code?










share|improve this question














sayhello.phtml



<!DOCTYPE html>
<html>
<head>
<h2>Wholesale and Dealer Inquiries Form</h2>
</head>
<body>
<table align="center">
<form action="<?php echo $block-
>getBaseUrl().'wholesaleapplication/index/post/';?>" method="post">
<tr>
<td><label> Business Name </label></td>
<td> <input type="text" name="name"></td>
</tr>
<tr>
<td><label> Contact Name </label></td>
<td><input type="text" name="cname"></td>
</tr>
<tr>
<td> <label> E-mail </label></td>
<td><input type="email" name="email"></td>
</tr>
<tr>
<td> <label> Address </label></td>
<td><input type="text" name="address">
<label> Street Address </label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="address2">
<label> Street Address line 2</label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="city">
<label>city</label></td>
<td><input type="text" name="state">
<label>state/province</label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="zipcode">
<label>postal zip/code</label></td>
</tr>
<tr>
<td></td>
<td><input type="text" name="areacode">
<label>area code</label></td>
<td><input type="text" name="phonenumber">
<label>phone number</label></td>
</tr>
<tr>
<td> <label class="form-label form-label-left form-label-auto" id="label_9" for="input_9"> Website </label></td>
<td><input type="text" name="website"></td>
</tr>
<tr>
<td> <label> Reseller Permit </label></td>
<td><input type="text" name="reseller"></td>
</tr>
<tr>
<td> <label> Description of Business </label></td>
<td><textarea name="description" ></textarea></td>
</tr>
<tr>
<td> <label> Additional Questions and Comments </label></td>
<td><textarea name="additional" ></textarea></td>
</tr>
<tr>
<td> <label> click to edit </label></td>
<td><input type="file"></td>
</tr>
<tr>
<td><button type="submit" name="submit">
Submit
</button></td>
</tr>

</form>





country dropdowncode



<?php $_countries = 
Mage::getResourceModel('directory/country_collection')
loadData()
toOptionArray(false) ?>
<?php if (count($_countries) > 0): ?>
<select name="country" id="country">
<option value="">-- Please Select --</option>
<?php foreach($_countries as $_country): ?>
<option value="<?php echo $_country['value'] ?>">
<?php echo $_country['label'] ?>
</option>
<?php endforeach; ?>
</select>
<?php endif; ?>


i want drop down near zip code in phtml file where to keep this country code?







magento2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 3 hours ago









Ashish RamchandaniAshish Ramchandani

878




878













  • you have tried Magento 1 code>

    – Amit Bera
    3 hours ago











  • can you please share me magento2 code

    – Ashish Ramchandani
    3 hours ago



















  • you have tried Magento 1 code>

    – Amit Bera
    3 hours ago











  • can you please share me magento2 code

    – Ashish Ramchandani
    3 hours ago

















you have tried Magento 1 code>

– Amit Bera
3 hours ago





you have tried Magento 1 code>

– Amit Bera
3 hours ago













can you please share me magento2 code

– Ashish Ramchandani
3 hours ago





can you please share me magento2 code

– Ashish Ramchandani
3 hours ago










1 Answer
1






active

oldest

votes


















3














Magento already has a block class which is available to provide country dropdown.



On your phtml files call the block and you will get country dropdown



<?php $countryBlock = $block->getLayout()->createBlock('MagentoDirectoryBlockData');?>

<?= $countryBlock->getCountryHtmlSelect($defValue = null, $name = 'country_id', $id = 'country', $title = 'Country');?>


You can set default $defValue,$name,$id as per as your wise.






share|improve this answer
























  • i have to keep this code in sayhello.phtml file right?

    – Ashish Ramchandani
    3 hours ago











  • yes, just you have to paste this code

    – Amit Bera
    3 hours ago











  • thankyou it works

    – Ashish Ramchandani
    3 hours ago











  • now i have to pass this in post varilable so what will be the name of the variable

    – Ashish Ramchandani
    3 hours ago











  • +1 simple and nice @AmitBera

    – G Prathap
    3 hours ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f262785%2fput-country-dropdown-in-phtml-file-in-magento2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














Magento already has a block class which is available to provide country dropdown.



On your phtml files call the block and you will get country dropdown



<?php $countryBlock = $block->getLayout()->createBlock('MagentoDirectoryBlockData');?>

<?= $countryBlock->getCountryHtmlSelect($defValue = null, $name = 'country_id', $id = 'country', $title = 'Country');?>


You can set default $defValue,$name,$id as per as your wise.






share|improve this answer
























  • i have to keep this code in sayhello.phtml file right?

    – Ashish Ramchandani
    3 hours ago











  • yes, just you have to paste this code

    – Amit Bera
    3 hours ago











  • thankyou it works

    – Ashish Ramchandani
    3 hours ago











  • now i have to pass this in post varilable so what will be the name of the variable

    – Ashish Ramchandani
    3 hours ago











  • +1 simple and nice @AmitBera

    – G Prathap
    3 hours ago
















3














Magento already has a block class which is available to provide country dropdown.



On your phtml files call the block and you will get country dropdown



<?php $countryBlock = $block->getLayout()->createBlock('MagentoDirectoryBlockData');?>

<?= $countryBlock->getCountryHtmlSelect($defValue = null, $name = 'country_id', $id = 'country', $title = 'Country');?>


You can set default $defValue,$name,$id as per as your wise.






share|improve this answer
























  • i have to keep this code in sayhello.phtml file right?

    – Ashish Ramchandani
    3 hours ago











  • yes, just you have to paste this code

    – Amit Bera
    3 hours ago











  • thankyou it works

    – Ashish Ramchandani
    3 hours ago











  • now i have to pass this in post varilable so what will be the name of the variable

    – Ashish Ramchandani
    3 hours ago











  • +1 simple and nice @AmitBera

    – G Prathap
    3 hours ago














3












3








3







Magento already has a block class which is available to provide country dropdown.



On your phtml files call the block and you will get country dropdown



<?php $countryBlock = $block->getLayout()->createBlock('MagentoDirectoryBlockData');?>

<?= $countryBlock->getCountryHtmlSelect($defValue = null, $name = 'country_id', $id = 'country', $title = 'Country');?>


You can set default $defValue,$name,$id as per as your wise.






share|improve this answer













Magento already has a block class which is available to provide country dropdown.



On your phtml files call the block and you will get country dropdown



<?php $countryBlock = $block->getLayout()->createBlock('MagentoDirectoryBlockData');?>

<?= $countryBlock->getCountryHtmlSelect($defValue = null, $name = 'country_id', $id = 'country', $title = 'Country');?>


You can set default $defValue,$name,$id as per as your wise.







share|improve this answer












share|improve this answer



share|improve this answer










answered 3 hours ago









Amit BeraAmit Bera

58.4k1475174




58.4k1475174













  • i have to keep this code in sayhello.phtml file right?

    – Ashish Ramchandani
    3 hours ago











  • yes, just you have to paste this code

    – Amit Bera
    3 hours ago











  • thankyou it works

    – Ashish Ramchandani
    3 hours ago











  • now i have to pass this in post varilable so what will be the name of the variable

    – Ashish Ramchandani
    3 hours ago











  • +1 simple and nice @AmitBera

    – G Prathap
    3 hours ago



















  • i have to keep this code in sayhello.phtml file right?

    – Ashish Ramchandani
    3 hours ago











  • yes, just you have to paste this code

    – Amit Bera
    3 hours ago











  • thankyou it works

    – Ashish Ramchandani
    3 hours ago











  • now i have to pass this in post varilable so what will be the name of the variable

    – Ashish Ramchandani
    3 hours ago











  • +1 simple and nice @AmitBera

    – G Prathap
    3 hours ago

















i have to keep this code in sayhello.phtml file right?

– Ashish Ramchandani
3 hours ago





i have to keep this code in sayhello.phtml file right?

– Ashish Ramchandani
3 hours ago













yes, just you have to paste this code

– Amit Bera
3 hours ago





yes, just you have to paste this code

– Amit Bera
3 hours ago













thankyou it works

– Ashish Ramchandani
3 hours ago





thankyou it works

– Ashish Ramchandani
3 hours ago













now i have to pass this in post varilable so what will be the name of the variable

– Ashish Ramchandani
3 hours ago





now i have to pass this in post varilable so what will be the name of the variable

– Ashish Ramchandani
3 hours ago













+1 simple and nice @AmitBera

– G Prathap
3 hours ago





+1 simple and nice @AmitBera

– G Prathap
3 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f262785%2fput-country-dropdown-in-phtml-file-in-magento2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

ORA-01691 (unable to extend lob segment) even though my tablespace has AUTOEXTEND onORA-01692: unable to...

Always On Availability groups resolving state after failover - Remote harden of transaction...

Circunscripción electoral de Guipúzcoa Referencias Menú de navegaciónLas claves del sistema electoral en...