当前位置: 移动技术网 > IT编程>开发语言>PHP > Bootstrap+PHP表单验证实例

Bootstrap+PHP表单验证实例

2019年03月07日  | 移动技术网IT编程  | 我要评论

大连影城,斗罗大陆之强奸朱竹清,你这个大胖子

 简单实用的bootstrap+php表单验证实例,非常适合初学者及js不熟悉者,还有ajax远程验证

 

js验证表单

 1 $(document).ready(function() { 
 2     $('#defaultform') 
 3             .bootstrapvalidator({ 
 4                 message: 'this value is not valid', 
 5                 feedbackicons: { 
 6                     valid: 'glyphicon glyphicon-ok', 
 7                     invalid: 'glyphicon glyphicon-remove', 
 8                     validating: 'glyphicon glyphicon-refresh' 
 9                 }, 
10                 fields: { 
11                     username: { 
12                         message: 'the username is not valid', 
13                         validators: { 
14                             notempty: { 
15                                 message: 'the username is required and can\'t be empty' 
16                             }, 
17                             stringlength: { 
18                                 min: 6, 
19                                 max: 30, 
20                                 message: 'the username must be more than 6 and less than 30 characters long' 
21                             }, 
22                             /*remote: { 
23                              url: 'remote.php', 
24                              message: 'the username is not available' 
25                              },*/ 
26                             regexp: { 
27                                 regexp: /^[a-za-z0-9_\.]+$/, 
28                                 message: 'the username can only consist of alphabetical, number, dot and underscore' 
29                             } 
30                         } 
31                     }, 
32                     email: { 
33                         validators: { 
34                             notempty: { 
35                                 message: 'the email address is required and can\'t be empty' 
36                             }, 
37                             emailaddress: { 
38                                 message: 'the input is not a valid email address' 
39                             } 
40                         } 
41                     }, 
42                     password: { 
43                         validators: { 
44                             notempty: { 
45                                 message: 'the password is required and can\'t be empty' 
46                             } 
47                         } 
48                     } 
49                 } 
50             }) 
51             .on('success.form.bv', function(e) { 
52                 // prevent form submission 
53                 e.preventdefault(); 
54  
55                 // get the form instance 
56                 var $form = $(e.target); 
57  
58                 // get the bootstrapvalidator instance 
59                 var bv = $form.data('bootstrapvalidator'); 
60  
61                 // use ajax to submit form data 
62                 $.post($form.attr('action'), $form.serialize(), function(result) { 
63                     console.log(result); 
64                 }, 'json'); 
65             }); 
66 });

 

php远程验证用户名

1 $username = $_post['username']; 
2  
3 echo json_encode(array( 
4     'message' => sprintf('welcome %s', $username), 
5 ));

本实例下载:

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网