欢迎来到六久阁织梦模板网!
织梦ajax提交表单及前端验证、前端提示以及30秒后再提交如何实现

织梦ajax提交表单及前端验证、前端提示以及30秒后再提交如何实现

浏览次数: 0

作者: 六久阁织梦模板网

信息来源: 六久阁

更新日期: 2020-07-18

文章简介

织梦ajax提交表单及前端验证、前端提示以及30秒后再提交前端代码 linkrel=stylesheethref=/static/css/zdialog.csslinkrel=stylesheethref=https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.cssscriptsrc=https://cdn.staticfile.org/

  • 正文开始
  • 热门文章

织梦ajax提交表单及前端验证、前端提示以及30秒后再提交前端代码

<link rel="stylesheet" href="/static/css/zdialog.css">
                <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  
                <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
                <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
                <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
                <!-- <link rel="stylesheet" href="/static/js/zdialog.js"> -->
                <script src="/static/js/zdialog.js"></script>
                <style>
                    .form-control{
                        height: 2.5rem;
                        font-size: .875rem;
                    }
        
                    input#btn-form1.btn.btn-default:focus{
                        border-color:#ccc;
                        webkit-box-shadow:none;
                        box-shadow:none;
                    }
        
                    input#btn-form2.btn.btn-default:focus{
                        border-color:#ccc;
                        webkit-box-shadow:none;
                        box-shadow:none;
                    }
        
                    .blank20{
                        clear: both;
                        height: 2rem;
                    }
                    label.error {
                        float: right;
                        margin-top: 5px;
                        margin-right: 5px;
                        color: red;
                        font-weight: 200;
                    }
                </style>
                <div class="container">
                    <h2 class="text-center"  style="font-weight: 800;">在线留言</h2>
                    <div class="row">
                        <div class="col-xs-12">
                            <form role="form"  id='form1'  method="post">
                                <div class="form-group">
                                    <label for="mianji">房屋面积 <em style="color: red;">*</em><small  style="color:#ccc;font-weight: 200;margin-left: 20px;">仅需输入数字,面积是平方米</small></label>
                                    <input type="text" class="form-control" id="mianji" 
                                           placeholder="请输入房屋面积" name="mianji" autocomplete="off">
                                </div>
                                <div class="form-group">
                                    <label for="name">姓名 <em style="color: red;">*</em></label>
                                    <input type="text" class="form-control" id="name" 
                                           placeholder="请输入姓名" name="name" autocomplete="off">
                                </div>
                                <div class="form-group">
                                    <label for="shouji">手机号 <em style="color: red;">*</em></label>
                                    <input type="text" class="form-control" id="shouji" 
                                           placeholder="请输入手机号" name="shouji" autocomplete="off">
                                </div>
                                
                               
                                <input  value="" type="hidden"  id="time"  name="time"  />
                                <script type="text/javascript">
                                                    window.onload = function(){
                                                    var nowDate = new Date();
                                                    var str = nowDate.getFullYear()+"-"+(nowDate.getMonth() + 1)+"-"+nowDate.getDate()+" "+nowDate.getHours()+":"+nowDate.getMinutes()+":"+nowDate.getSeconds();
                                                    document.getElementById("time").value=str;
                                                    }
                                </script>
                                <input type="hidden" name="dede_fields" value="name,text;shouji,text;time,text;mianji,text" />
                                <input type="hidden" name="dede_fieldshash" value="15b519c934da3a1f3512a53e131f5522" />
                                <input  type="button" class="btn btn-default"  id="btn-form1"  value="提交" onclick="return false;" style="font-size: .96240942rem;color:#fff;width: 100%; height: 3rem; margin: 0px auto; background-color: rgb(255, 156, 0); border-radius: 3px; line-height: 2.75rem;">
                            </form>
                        </div>
                        
                    </div>
                   
                </div>
        
                <script>
                    $(function(){
        
                                  // 手机号验证
                                jQuery.validator.addMethod("isPhone", function(value, element) {
                                var length = value.length;
                                var mobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
                                return this.optional(element) || (length == 11 && mobile.test(value));
                                }, "请填写正确的手机号码");
                                // 中文姓名验证,先验证中文,再验证个数
                                jQuery.validator.addMethod('chcharacter', function(value, element){
                                var tel = /^[u4e00-u9fa5]+$/;
                                console.log(tel.test(value))
                                return this.optional(element) || !(tel.test(value));
                                }, '请输入汉字');
        
                                $('#btn-form1').on('click',function(){
        
                                    var anniu=this
                                    // 设置再次提交的时间限制
                                    var wait = 30;
                                    function time_limit(obj) {
                                    if (wait == 0) {
                                        obj.removeAttribute("disabled");
                                        obj.value = "提交";
                                        wait = 20;
                                    } else {
                                        obj.setAttribute("disabled", true);
                                        obj.value = "重新提交(" + wait + ")";
                                        wait--;
                                        setTimeout(function () {
                                            time_limit(obj)
                                        },
                                            1000)
                                    }
                                    }
        
                                    // 先验证,并且设置一个状态,验证通过后,才能提交
                                
                                    var status= $("#form1").validate({
                                            rules : {
                                                mianji:{
                                                    required : true,
                                                    number:true
                                                },
                                                name : {
                                                    required : true,
                                                    chcharacter:true,
                                                    rangelength:[2,5]
                                                },
                                                shouji : {
                                                    required : true,
                                                    isPhone:true
                                                }
                                            },
                                            messages : {
                                                mianji : {
                                                    required : '请输入房屋面积',
                                                    number:'请输入数字,面积为平方米',
                                                },
                                                name : {
                                                    required : '请输入姓名',
                                                    chcharacter:'请输入汉字',
                                                    rangelength:'名字中最少2个汉字,最多5个'
        
        
                                                },
                                                shouji : {
                                                    required : '请填写手机号',
                                                    isPhone : '手机号格式不正确',
                                                }
                                            }
                                        });
                                        console.log(status.form())
        
                                    // 根据验证的状态,进行判断,再提交
        
                                    if(status.form()){
                                        // var list={};
                                        // var diag = new Dialog();
                                        var name=$('#name').val()
                                        var mianji=$('#mianji').val()
                                        var shouji=$('#shouji').val()
                                        var time=$('#time').val()
                                        var dataString = 'name='+ name + '&mianji='+mianji+'平方米&action=post&shouji=' + shouji + '&time=' + time + '&diyid=2&do=2&dede_fields=name,text;shouji,text;time,text;mianji,text&dede_fieldshash=15b519c934da3a1f3512a53e131f5522&submit=提交';
                                        // console.log(list)
                                        $.ajax({
                                                //请求方式
                                                type : "POST",
                                                //请求的媒体类型
                                                // contentType: "application/json;charset=UTF-8",
                                                // 响应的json返回值
                                                datatype: "json",
                                                //请求地址
                                                url : "http://www.XXX.com/plus/diy.php",
                                                //数据,json字符串
                                                data : dataString,
                                                //请求成功
                                                success : function(result) {
                                                    // return false;
                                                    // console.log(result);
                                                    if(result.code==1){
                                                        $.DialogByZ.Alert({Title: "温馨提示", Content: "提交成功,请耐心等待报价",BtnL:"确定"})
        
        
                                                        // 请求成功之后,执行时间限制的函数
                                                        console.log(anniu);
                                                       time_limit(anniu)
        
                                                    }
                                                    
                                                },
                                                //请求失败,包含具体的错误信息
                                                error : function(e){
                                                    console.log(e.status);
                                                    console.log(e.responseText);
                                                }
                                            })
                                    }else{
                                        return false;
                                    }
                            
                                })
                    })
                </script>
        
                <div class="blank20"></div>

织梦自定义表单diy.php里代码

header('Content-Type:application/json; charset=utf-8');
       if($dsql->ExecuteNoneQuery($query))
        {
            $id = $dsql->GetLastID();
            if($diy->public == 2)
            {
                //diy.php?action=view&diyid={$diy->diyid}&id=$id
                // $goto = "diy.php?action=list&diyid={$diy->diyid}";
                // $bkmsg = '发布成功,现在转向表单列表页...';
                $data=array('code'=>1,'msg'=>'提交成功,请耐心等待');
                echo json_encode($data);
            }
            else
            {
               
                // $goto = !empty($cfg_cmspath) ? $cfg_cmspath : '/';
                // $bkmsg = '发布成功,请等待管理员处理...';
                $data=array('code'=>1,'msg'=>'提交成功,请耐心等待');
                echo json_encode($data);
            }
            // showmsg($bkmsg, $goto);
            // showmsg('nihao', 'http://www.baidu.com');
        }
    }


织梦二次开发QQ群

本站客服QQ号:862782808(点击左边QQ号交流),群号(383578617) DedeCMS织梦教程QQ群 如果您有任何织梦问题,请把问题发到群里,阁主将为您写解决教程!

转载请注明: 织梦模板 » 织梦ajax提交表单及前端验证、前端提示以及30秒后再提交如何实现

标签:
  • 织梦dedecms手机站m目录下不生成index.html实现动态更新
    阅读
    用 织梦建站 会手机站首页不更新的苦恼,每次 PC 更新,要去删除 m 目录下的 index.html ,手机站首页才会更新,这样很麻烦,通过以下修改,让手机站首页是动态的,不生成 index.html , PC 端更新后,手机端首页自动更新。 把 \m\index.php 里面的 $row[sho...
  • 织梦Fatal error: Call to undefined function make_hash() in /dede/sys_info.php on line 201的解决方法
    阅读
    织梦系统安装好后,进入后台,出现Fatal error: Call to undefined function make_hash() in /dede/sys_info.php on line 201 一般出现这个问题是因为升级网站引起的。我们可以直接把错误提示这段代码删除或者屏蔽就行了。 打开/dede/sys_info.php,找到201...
  • 织梦Dedecms 5.7 火车头采集免登陆发布接口适配PHP7.X插件
    阅读
    最近有粉丝说,之前用的火车头发布文章时,用免登陆接口在PHP7.0环境中显示空白,于是今天抽空更新了一下插件(话说,DedeCms早期版本无法在PHP7.X运行,用最新版的!),那么接下来的代码就是插件发布模块无须变更,只需要变更接口插件就可以了 ?php/*/////...
  • 织梦dedecms系统多城市分站功能开发思路
    阅读
    当前很多人用织梦dedecms系统建站,多城市分站对地方性长尾关键词和全国市场的推广有着很大的帮助,今天和大家分享下如何实现织梦dedecms系统多城市分站功能。 方法/步骤 织梦dede城市分站有三种方法: 第一种是建立N多个模板,有多少个城市建立多少个模板,...
  • 织梦dedecms提交自定义表单后发送到指定邮箱
    阅读
    网上很多教程都是用 dedecms 自带的邮件库发送邮件,而且是写死要发送的字段内容,今天我们用 phpmailer 来给站长发送自定义表单提交的数据到指定邮箱上 (QQ 邮箱, 163 邮箱都可以 ) ,不写死任何东西,有什么字段就提交发送什么字段。 操作之前,我们要先...
  • dedecms织梦ckplayer视频播放器插件详细安装教程
    阅读
    织梦 ckplayer 视频播放器插件安装步骤: 第一步、下载安装插件。下载地址:点击此处 将下载下来的压缩包中的相应编码的模块文件解压出来再上传到织梦程序的 data/module/ 文件夹内或者直接在后台模块管理菜单里面选择上传新模块安装即可。如下图: 1.1 )上...
  • 织梦5.7火车头免登陆文章发布模块采集后自动更新织梦整站
    阅读
    织梦5.7火车头免登陆文章发布模块采集后自动更新织梦整站详细步骤: 1、下载文档后,把DedeCMS免登陆接口文章发布模块DedeCMS 5.7 免登陆接口文章发布模块.wpm复制到火车头采集规则文件夹Module下; 2、选择您网站对应的接口文件.如您网站是gbk编码,请选择 g...
  • 织梦采集侠破解版自动采集触发教程24小时触发自动审核自动更新
    阅读
    最新采集侠V2.9.2破解版,可以在网站进行全自动数据采集,采集侠破解版可以帮助用户快速提升自己网站的Seo排名。 织梦采集侠是一款基于dedecms的一套根据关键词自动采集,无须编写复杂的采集规则,自动伪原创,自动发布内容的绿色插件。简单配置好后能实现24...
  • 织梦dedecms网站添加打赏功能
    阅读
    有时我们看到别人家的织梦dedecms网站有打赏功能,是不是羡慕嫉妒恨呢?今天我来给大家讲讲织梦网站怎么添加支付宝、微信打赏功能。 二、首先登陆畅言后台(没有畅言账号的首先注册账号) 三、进入后台,找到实验室--打赏 四、设置配置信息,保存。 五、复制...
  • 织梦火车头采集免登陆接口采集文章后自动更新栏目、首页、文章页,实现自动化采集
    阅读
    最近用织梦dedecms程序采集文章时候,发现每次采集都要去后台更新一下文章、栏目、上下篇以及首页,操作起来真心麻烦,后面在网上收集了一些代码以及经过自己调试,发现居然可以自动更新文章页以及栏目、首页。真心爽,这样子就能稳稳的挂机采集了哈。这是免...
收藏此文 打赏本站

如本文对您有帮助,就请六久阁织梦模板网抽根烟吧!

  • 支付宝打赏
    支付宝扫描打赏
    微信打赏
    微信扫描打赏
织梦网站js/jquery操作iframe框架
« 上一篇 2020年07月18日
织梦网站js提交表单的时候,30秒后才能提交第二次如何写
下一篇 » 2020年07月18日

精彩评论

有问题在这里提问,阁主会为你解决!
  • 全部评论(0
    还没有评论,快来抢沙发吧!
推荐精品模板更多
响应式照明灯饰类织梦模板(自适应手机端)
更新时间:2018-04-26

人已经看过了!

绿色新闻资讯织梦模板带测试数据
更新时间:2017-08-10

人已经看过了!

营销型印刷包装打带类企业网站织梦模板(带手机端)
更新时间:2020-04-30

人已经看过了!

织梦简洁好看小说模板源码下载带手机端
更新时间:2019-12-15

人已经看过了!