Heim  >  Artikel  >  Backend-Entwicklung  >  Beispiel für die Bootstrap+PHP-Formularvalidierung

Beispiel für die Bootstrap+PHP-Formularvalidierung

little bottle
little bottlenach vorne
2019-04-18 17:00:432412Durchsuche

Bootstrap ist ein einfaches, intuitives und leistungsstarkes Front-End-Entwicklungsframework, das auf HTML, CSS und JavaScript basiert und von den Designern Mark Otto und Jacob Thornton von der Twitter Company in den USA entwickelt wurde und die Webentwicklung beschleunigt. In diesem Artikel geht es hauptsächlich um ein einfaches und praktisches Beispiel für die Bootstrap + PHP-Formularüberprüfung, das sich sehr gut für Anfänger und diejenigen eignet, die mit js nicht vertraut sind. Interessierte können auch gemeinsam etwas darüber lernen.

JS-Validierungsformular


 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 });

Empfohlene Kurse: Bootstrap-Video-Tutorial

PHP-Remote-Verifizierungs-Benutzername


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

Empfohlener Kurs: PHP Video-Tutorial

Das obige ist der detaillierte Inhalt vonBeispiel für die Bootstrap+PHP-Formularvalidierung. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Dieser Artikel ist reproduziert unter:cnblogs.com. Bei Verstößen wenden Sie sich bitte an admin@php.cn löschen