I am trying to use my form to override my PHP variable $country_code to either CA, US or EU based on the option you select from the drop down form (country_show). I am using Cloudflare on my site so
$country_code = $_SERVER["HTTP_CF_IPCOUNTRY"];
works for me. I have been learning PHP and HTML for only a few weeks now, and know nothing of javascript. The script below was a basic hide div function which was found online. If anybody has any suggestions on how to use the dropdown to override the $country_code variable, please let me know. My knowledge in HTML and PHP is very limited.
<?php
$country_code = $_SERVER["HTTP_CF_IPCOUNTRY"];
?>
<script>
function showhide()
{
var div = document.getElementById("country_show");
if (div.style.display !== "none") {
div.style.display = "none";
}
else {
div.style.display = "block";
}
}
</script>
<div id="country_show">
<?php
if ($country_code == "CA") {
$message = "We have set your delivery country to Canada. If this is incorrect, please select your country";
}
elseif ($country_code == "US") {
$message = "We have set your delivery country to United States. If this is incorrect, please select your country";
}
else {
$message = "We have set your shipping charges to International. If this is incorrect, please select your country";
}
echo $message
?>
<form id="country_show">
<select>
<option value="">Choose location</option>
<option>Canada</option>
<option>United States</option>
<option>International</option>
</select>
</form>
<button id="button" onclick="showhide()">Hide</button>
</div>
</div>- Add one, see if it makes it kick in.<option>United States</option>should be<option value="USA">United States</option>etc.