How to use form validation Plug-ins ValidForm

Source: Internet
Author: User

The first step: the introduction of JS and CSS in the foreground HTML file:

<link rel= "stylesheet" href= ' __root__/public/js/validform/style.css '/>

<script src= ' __root__/public/js/jquery.js ' ></script>

<script src= ' __root__/public/js/validform/validform.js ' ></script>

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/tools/

Step two: Front desk form:

1 datatype: Sets the data type of the text box content, for example: Datatype= "n6-6": six digits, datatype= ' *6-12 ': password is 6--12 bit (alphanumeric or other symbols)

2 errormsg: Information output When an error occurs in the input content

3 nullmsg: Information that is output when the content is empty

4 Ajaxurl: Methods for submitting to background execution

5 <font class= "Validform_checktip" ></FONT>: Output information

For example:

<form class= ' form ' action= ' login ' method= ' post ' name= ' MyForm ' >

<div>

&NBSP User type:

<select name= ' user_type ' id= ' user_type ' style= ' width:135px ' >

<option value= ' 1 ' > Teachers </option>

<option value= ' 2 ' > Admin </option>

</select><br/></br>

</div>

<div>

&NBSP account Number: <input type= ' text ' id= ' idcard ' name= ' idcard ', ' style= ' width:135px ' "ajaxurl= ' Datatype= "n6-6" errormsg= account number is 6 digits "nullmsg=" account cannot be empty! "/><font class=" Validform_checktip "></font><br/><br/>

</div>

<div>

&nbsp Password: <input type= ' password ' id= ' pwd ' name= ' ' pwd ', ' style= ' width:135px ' datatype= ', ' *6-12 ' ' errormsg= ' the password is 6--12 digits nullmsg= ' Please enter password '/><font class= ' Validform_checktip ' ></font><br/><br/>

</div>

<div class= ' pas ' >

<input id= ' check ' type= ' checkbox '/>&nbsp<font id= ' keep ' color= ' darkorange ' > Remember password </font>

/div><br/><br/>

<center>

<input type= ' button ' name= ' login ' value= ' log in '/>

&nbsp&nbsp

<input type= ' button ' name= ' reset ' value= ' reset '/>

</center>

</form>

The third step: JS file:

$ (". Form"). ValidForm ({

Form submission

Ignorehidden:true,

Postonce:true,

Ajaxpost:true,

Tiptype:function (MSG,O,CSSCTL) {

if (!o.obj.is ("form")) {

var objtip=o.obj.siblings (". Validform_checktip ");

Cssctl (Objtip,o.type);

Objtip.text (msg);

}

},

Callback:function (data) {

callback function

Switch (data) {

Case 1:

window.location.href=$ (' #url '). Val () + '/test/test/test_manage ';

Alert (' Landing success ');

Break

Case 2:

window.location.href=$ (' #url '). Val ();

Break

Case 3:

$ (' input[name= "pwd"]). Val (');

Alert (' Password input error ');

Break

Case 4:

$ (' input[name= "Idcard"]). Val (');

$ (' input[name= "pwd"]). Val (');

Alert (' Login failed ');

Break

}

}

});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.