短信验证码发送成功后 点击提交按钮显示验证码未发送
验证码代码
<button class="btn" onclick="dr_ajax_url('/index.php?s=form&c=api&m=send_code&&id='+$('#dr_dianhua2').val())" type="button" >获取验证码</button>
<button type="button" onclick="dr_ajax_submit('{$post_url}', 'myform2', '2000', '{$rt_url}')" class="btn btn-warning btn-block mt15" >免费领取</button>控制器代码
<?php namespace Phpcmf\Controllers;
/**
* 二次开发时可以修改本文件,不影响升级覆盖
*/
class Xfbd extends \Phpcmf\Home\Form
{
public function index() {
$this->_Home_List();
}
public function show() {
$this->_Home_Show();
}
public function post() {
$code = \Phpcmf\Service::L('Form')->get_mobile_code($phone);
if (!$code) {
$this->_json(0, dr_lang('没有发送验证码'));
} elseif ($code != $_POST['sms']) {
$this->_json(0, dr_lang('验证码不正确'));
}
$this->_Home_Post();
}
}api代码:
<?php namespace Phpcmf\Controllers;
// 用户api
class Api extends \Phpcmf\Common
{
/**
* 发送验证码
*/
public function send_code() {
$phone = dr_safe_replace(\Phpcmf\Service::L('input')->get('id'));
if (!$phone) {
$this->_json(0, dr_lang('手机号码未填写'), ['field' => 'phone']);
} elseif (!\Phpcmf\Service::L('Form')->check_phone($phone)) {
$this->_json(0, dr_lang('手机号码格式不正确'), ['field' => 'phone']);
}
if (\Phpcmf\Service::L('Form')->get_mobile_code($phone)) {
// 验证操作间隔
$this->_json(1, dr_lang('已经发送稍后再试'));
}
$code = rand(100000, 999999);
$rt = \Phpcmf\Service::M('member')->sendsms_code($phone, $code);
if (!$rt['code']) {
$this->_json(0, dr_lang('发送失败'));
}
\Phpcmf\Service::L('Form')->set_mobile_code($phone, $code);
$this->_json(1, dr_lang('验证码发送成功'));
}
}使用的是阿里云的接口 手机可以获得验证码 但是提交表单显示没有发送
{php extract(dr_get_form_post_value('biaodan'))} <form action="" class="form-horizontal" method="post" name="myform" id="myform2"> {$form} <div class="fc-form-body"> <div class="p_r mt15" id="dr_row_xingming"> <input type="text" class="form-control pl30" name="data[xingming2]" id="dr_xingming2" placeholder="请输入名字" /> <i class="glyphicon glyphicon-user"></i> </div> <div class="p_r mt15" id="dr_row_dianhua"> <input type="text" class="form-control pl30" name="data[dianhua2]" id="dr_dianhua2" placeholder="请输入手机号" /> <i class="glyphicon glyphicon-phone"></i> </div> <div class="input-group input-large mt15"> <input class="form-control placeholder-no-fix" type="text" autocomplete="off" id="dr_sms" name="sms"> <div class="input-group-btn"> <button class="btn" onclick="dr_ajax_url('/index.php?s=form&c=api&m=send_code&&id='+$('#dr_dianhua2').val())" type="button" >获取验证码</button> </div> </div> </div> <button type="button" onclick="dr_ajax_submit('{$post_url}', 'myform2', '2000', '{$rt_url}')" class="btn btn-warning btn-block mt15" >免费领取</button> </form><?php namespace Phpcmf\Controllers; /** * 二次开发时可以修改本文件,不影响升级覆盖 */ class Xfbd extends \Phpcmf\Home\Form { public function index() { $this->_Home_List(); } public function show() { $this->_Home_Show(); } public function post() { if (IS_POST) { $phone = $_POST['data']['dianhua2']; $code = \Phpcmf\Service::L('Form')->get_mobile_code($phone); if (!$code) { $this->_json(0, dr_lang('没有发送验证码')); } elseif ($code != $_POST['sms']) { $this->_json(0, dr_lang('验证码不正确')); } } $this->_Home_Post(); } }