Home  >  Article  >  Web Front-end  >  Validform layer implements beautiful form validation effects_jquery

Validform layer implements beautiful form validation effects_jquery

WBOY
WBOYOriginal
2016-05-16 15:19:371868browse

Validform is an excellent form validation plug-in, and layer is an excellent pop-up window plug-in. Let’s take a look at the sparks between the two through examples

First introduce jquery, Validform and layer

<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="http://res.layui.com/lay/lib/layer/src/layer.js"></script> 
<script type="text/javascript" src="http://lib.h-ui.net/Validform/5.3.2/Validform.min.js"></script> 

HTML

<form action="post.php" method="post" name="form" class="form form-horizontal" id="form-Validform"> 
  <div class="row cl"> 
   <label class="form-label col-3"><span class="c-red">*</span>用户昵称:</label> 
   <div class="formControls col-8"> 
    <input type="text" class="input-text" value="" placeholder="可使用3-16位中英文字符" id="uname" name="uname" datatype="*2-16" nullmsg="用户昵称不能为空"> 
   </div> 
  </div> 
  <div class="row cl"> 
   <label class="form-label col-3"><span class="c-red">*</span>用户密码:</label> 
   <div class="formControls col-8"> 
    <input type="text" class="input-text" value="" placeholder="5-20位,范围[0-9a-zA-Z_@!.-]" id="pwd" name="pwd" datatype="/\w{5,20}/i" nullmsg="用户密码不能为空"> 
   </div> 
  </div> 
   <div class="row cl"> 
     <label class="form-label col-3"><span class="c-red">*</span>Email:</label> 
     <div class="formControls col-8"> 
      <input type="text" class="input-text" value="" placeholder="****@***.***" id="email" name="email" datatype="e" nullmsg="Email不能为空"> 
     </div> 
   </div> 
   <div class="row cl"> 
     <label class="form-label col-3"></label> 
     <div class="formControls col-8"> 
      <a href="javascript:;" id="safecodes" style="color:red"><&#63;php echo $safecode; &#63;></a> 
     </div> 
   </div> 
  </div> 
  <div class="row cl" style="text-align:center"> 
    <input class="btn btn-primary radius" type="submit" value="  提交  "> 
  </div> 
  </form> 

JS

<script type="text/javascript"> 
$(function(){ 
  $("#form-Validform").Validform({ 
    tiptype:4, 
    ajaxPost:true, 
    callback:function(data){ 
      if(data.status==1){ 
        layer.msg(data.info, {icon: data.status,time: 1000}, function(){ 
          location.reload();//刷新页面 
          });  
      } 
      else{ 
        layer.msg(data.info, {icon: data.status,time: 3000}); 
      } 
    } 
  }); 
  $('#safecodes').click( function () { 
    $('#safecode').val($('#safecodes').text()); 
  }); 
}); 
</script> 

Server returns

{"info":"\u6210\u529f","status":1,"url":""} 

This example process: click submit->verify the form item by item->complete the verification ajax submission->judge based on the returned information->pop-up message

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn