I’m new and right now i’m practicing create form with two fields (phone number and country). I’m using intl-tel-input from https://github.com/jackocnr/intl-tel-input and i wonder can i get selected option country using PHP while the data using intl-tel-input. Here’s my HTML & PHP code
<div class="form-group">
<label for="exampleFormControlInput1">Country of Origin</label>
<select class="custom-select" id="country" name="country" value="<?=$pecah2['origin_country'] ?>" <?php if($pecah2['origin_country'] = $pecah2['origin_country']){echo 'selected="selected"';} ?>></select>
</div>
<div class="form-group">
<label for="exampleFormControlInput1">Phone Number</label><br>
<input type="text" class="form-control" name="phonenumber" id="phone" required value="<?= $pecah2['phone_number'] ?>">
</div>
JS
<script src="https://code.jquery.com/jquery-3.6.0.min.js" type="text/javascript"></script>
<script src="assets/build/js/intlTelInput.js" type="text/javascript"></script>
<script src="assets/build/js/intlTelInput.min.js" type="text/javascript"></script>
<script>
var input = document.querySelector("#phone");
var countryData = window.intlTelInputGlobals.getCountryData();
var addressDropdown = document.querySelector('#client_country');
var iti = window.intlTelInput(input, {
utilsScript :'assets/build/js/utils.js'
});
for (var i = 0; i < countryData.length; i++){
var country = countryData[i];
var optionNode = document.createElement("option");
optionNode.value = country.iso2;
var textNode = document.createTextNode(country.name);
optionNode.appendChild(textNode);
addressDropdown.appendChild(optionNode);
}
addressDropdown.value = iti.getSelectedCountryData().iso2;
input.addEventListener('countrychange',function(){
addressDropdown.value = iti.getSelectedCountryData().iso2;
});
addressDropdown.addEventListener('change', function(){
iti.setCountry(this.value);
});
</script>
i’m practicing by different youtube videos by the way