tp5留言验证问题

浏览:116 发布日期:2018/11/09 分类:ThinkPHP5专区
<?php
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
    public function index()
    {
        return $this->fetch();
    }
    public function add()
    {
        if(request()->isPost()){
            $captcha = input('post.');

            if(!captcha_check($captcha['verifyCode'])) {
                // 校验失败
                $this->error('验证码不正确');
            }else{
                $data=[
                    'college'=>input('college'),
                    'major'=>input('major'),
                    'num'=>input('num'),
                    'name'=>input('name'),
                    'sex'=>input('sex'),
                    'nation'=>input('nation'),
                    'card'=>input('card'),
                    'region'=>input('region1').input('region2').input('region3'),
                    'tel'=>input('tel'),
                    'double_trapped_student'=>input('double_trapped_student'),
                    'obtain_employment'=>input('obtain_employment'),
                    'start_company_name'=>input('start_company_name'),
                    'start_company_time'=>input('start_company_time'),
                    'start_company_scale'=>input('start_company_scale'),
                    'start_company_benefit'=>input('start_company_benefit'),
                    'obtain_class'=>input('obtain_class'),
                    'obtain_company_name'=>input('obtain_company_name'),
                    'obtain_company_class'=>input('obtain_company_class'),
                    'obtain_company_industry'=>input('obtain_company_industry'),
                    'obtain_company_position'=>input('obtain_company_position'),
                    'obtain_company_add'=>input('obtain_company_add1').input('obtain_company_add2').input('obtain_company_add3'),
                    'no_obtain_causation'=>input('no_obtain_causation'),
                    'addtime'=> date("Y-m-d H:i:s",time()),
                    'ip'=>request()->ip(),
                ];
                $db=\think\Db::name('jymsg')->insert($data);
                if($db){
                    return $this->success('添加成功');
                }else{
                    return $this->error('添加失败');
                }
                return;
            }

        }


        return $this->fetch();
    }
}
这是我写的留言,但如何写验证判断呢?就是比如姓名这个空我不想为空,并且限制字数。
最佳答案
评论( 相关
后面还有条评论,点击查看>>