How to get country code as POST variable?

I like script using countries like https://intl-tel-input.com/
How to get POST value also for the specific country as it is a separate value?

<input id="phone" class="form-control" autocomplete="off" placeholder="(XXX) 555-0123" type="tel">

use getSelectedCountryData and put it in another input

Will this be the correct code?

//HTML
<input type="tel" id="phone">
<input id="phonefull" type="hidden" name="phonenumber">
<input id="callingcode" type="hidden" name="callingcode">

//Javascript
$("#calling_code").val($("#phone").intlTelInput("getSelectedCountryData").dialCode);   

//PHP
$_REQUEST['phonenumber']
$_REQUEST['callingcode']

Does it do what you expected it to do?

function send_name(selectObjectI) {
        var value = selectObjectI.value;
        $.ajax({
            type: "POST",
            url: "http://localhost/php/protected/form_addnews.php",
            data:{c_php_value: value}

        });
  1. I have validated and it is mistake in Javascript code: SyntaxError: missing } after function body
    Modified:
function send_name(selectObjectI) {
  var value = selectObjectI.value;
  $.ajax(
    {
    type: "POST",
    url: "http://localhost/php/protected/form_addnews.php",
    data: {c_php_value: value}

    }
  );
}
  1. So, specific fields:phonenumber or any POST fileds will be simple detected using PHP code with $_REQUEST[‘phonenumber’]?

did you try it?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.