PHP Make 手机验证字段

标签 php html

我正在制作一个表格,其中有一个手机号码输入字段,但我似乎无法让它正常工作。 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 = 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")
);

关于PHP Make 手机验证字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34422822/

相关文章:

javascript - 使用 dom 创建带有样式标签的 @font-face 不能正常工作?

javascript - 对未附加的 HTML 元素运行 document.getElementById

javascript - 从两个不同的表中选择相同索引的行

php - 检查字符串中是否存在单词数组

php - SQL_CALC_FOUND_ROWS 返回错误

php - HTML 表单不提交到 MYSQL 数据库

php - 如何从包含 0 值的 SQL 中获取最近 7 天的单独总和

javascript - 使用具有相同类名的 jQuery 选择 div

html - WCAG 指南(CSS+HTML+Javascript)

php - 返回第一个字符为字母且相当于重音字符的行