PHP Make Mobile验证字段


PHP Make Mobile Verification Field

我正在制作一个表单,其中有一个手机号码的输入字段,但我似乎无法使其正常工作。PHP代码获取IP和国家代码,然后列出可供选择的选项列表。国家代码、国旗和名称在一个数组中:

<?php
$countries array();
$countries[] = array("code"=>"AF","name"=>"Afghanistan","d_code"=>"+93", "img"=>"https://checkmobi.com/static/images/flags/AF-32.png");
$countries[] = array("code"=>"AL","name"=>"Albania","d_code"=>"+355", "img"=>"https://checkmobi.com/static/images/flags/AL-32.png");
$countries[] = array("code"=>"DZ","name"=>"Algeria","d_code"=>"+213", "img"=>"https://checkmobi.com/static/images/flags/DZ-32.png");
$countries[] = array("code"=>"AS","name"=>"American Samoa","d_code"=>"+1", "img"=>"https://checkmobi.com/static/images/flags/AS-32.png");
$countries[] = array("code"=>"AD","name"=>"Andorra","d_code"=>"+376", "img"=>"https://checkmobi.com/static/images/flags/AD-32.png");
.
.
.
$ip = $_SERVER['REMOTE_ADDR'];
$json = file_get_contents("http://ipinfo.io/{$ip}");
$details = json_decode($json);
$country_code = $details->country;
echo '<select name="mobile_verification">';
foreach ($countries as $country){
echo '<option value="'.$country['d_code'].'">'.$country['name'].'</option>';
}
echo '</select>';
?>

所以,这是一个代码示例,我想要的是复制这样的东西https://www.cognalys.com/#单击"Web Demo",即此处的手机号码字段。我想显示标志,然后输入字段与拨号代码的自动填充。任何指导或任何事情都会有所帮助。

我认为您没有正确创建countries数组,请尝试以下操作:

$countries = array(
  array("code"=>"AF","name"=>"Afghanistan","d_code"=>"+93", "img"=>"https://checkmobi.com/static/images/flags/AF-32.png"),
  array("code"=>"AL","name"=>"Albania","d_code"=>"+355", "img"=>"https://checkmobi.com/static/images/flags/AL-32.png"),
  array("code"=>"DZ","name"=>"Algeria","d_code"=>"+213", "img"=>"https://checkmobi.com/static/images/flags/DZ-32.png"),
  array("code"=>"AS","name"=>"American Samoa","d_code"=>"+1", "img"=>"https://checkmobi.com/static/images/flags/AS-32.png"),
  array("code"=>"AD","name"=>"Andorra","d_code"=>"+376", "img"=>"https://checkmobi.com/static/images/flags/AD-32.png")
);