PageSourceSearch

http://gccvirtual.com/home/public/mamba/assets/vendor/php-email-form/validate.js

js gccvirtual.com collected 2026-10-06 09:31:43 UTC 5,020 bytes, 165 lines download raw bytes

1/**
2* PHP Email Form Validation - v2.1
3* URL: https://bootstrapmade.com/php-email-form/
4* Author: BootstrapMade.com
5*/
6!(function($) {
7  "use strict";
8
9  $('form.php-email-form').submit(function(e) {
10    e.preventDefault();
11    
12    var f = $(this).find('.form-group'),
13      ferror = false,
14      emailExp = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i;
15
16    f.children('input').each(function() { // run all inputs
17     
18      var i = $(this); // current input
19      var rule = i.attr('data-rule');
20
21      if (rule !== undefined) {
22        var ierror = false; // error flag for current input
23        var pos = rule.indexOf(':', 0);
24        if (pos >= 0) {
25          var exp = rule.substr(pos + 1, rule.length);
26          rule = rule.substr(0, pos);
27        } else {
28          rule = rule.substr(pos + 1, rule.length);
29        }
30
31        switch (rule) {
32          case 'required':
33            if (i.val() === '') {
34              ferror = ierror = true;
35            }
36            break;
37
38          case 'minlen':
39            if (i.val().length < parseInt(exp)) {
40              ferror = ierror = true;
41            }
42            break;
43
44          case 'email':
45            if (!emailExp.test(i.val())) {
46              ferror = ierror = true;
47            }
48            break;
49
50          case 'checked':
51            if (! i.is(':checked')) {
52              ferror = ierror = true;
53            }
54            break;
55
56          case 'regexp':
57            exp = new RegExp(exp);
58            if (!exp.test(i.val())) {
59              ferror = ierror = true;
60            }
61            break;
62        }
63        i.next('.validate').html((ierror ? (i.attr('data-msg') !== undefined ? i.attr('data-msg') : 'wrong Input') : '')).show('blind');
64      }
65    });
66    f.children('textarea').each(function() { // run all inputs
67
68      var i = $(this); // current input
69      var rule = i.attr('data-rule');
70
71      if (rule !== undefined) {
72        var ierror = false; // error flag for current input
73        var pos = rule.indexOf(':', 0);
74        if (pos >= 0) {
75          var exp = rule.substr(pos + 1, rule.length);
76          rule = rule.substr(0, pos);
77        } else {
78          rule = rule.substr(pos + 1, rule.length);
79        }
80
81        switch (rule) {
82          case 'required':
83            if (i.val() === '') {
84              ferror = ierror = true;
85            }
86            break;
87
88          case 'minlen':
89            if (i.val().length < parseInt(exp)) {
90              ferror = ierror = true;
91            }
92            break;
93        }
94        i.next('.validate').html((ierror ? (i.attr('data-msg') != undefined ? i.attr('data-msg') : 'wrong Input') : '')).show('blind');
95      }
96    });
97    if (ferror) return false;
98
99    var this_form = $(this);
100    var action = $(this).attr('action');
101
102    if( ! action ) {
103      this_form.find('.loading').slideUp();
104      this_form.find('.error-message').slideDown().html('The form action property is not set!');
105      return false;
106    }
107    
108    this_form.find('.sent-message').slideUp();
109    this_form.find('.error-message').slideUp();
110    this_form.find('.loading').slideDown();
111
112    if ( $(this).data('recaptcha-site-key') ) {
113      var recaptcha_site_key = $(this).data('recaptcha-site-key');
114      grecaptcha.ready(function() {
115        grecaptcha.execute(recaptcha_site_key, {action: 'php_email_form_submit'}).then(function(token) {
116          php_email_form_submit(this_form,action,this_form.serialize() + '&recaptcha-response=' + token);
117        });
118      });
119    } else {
120      php_email_form_submit(this_form,action,this_form.serialize());
121    }
122    
123    return true;
124  });
125
126  function php_email_form_submit(this_form, action, data) {
127    $.ajax({
128      type: "POST",
129      url: action,
130      data: data,
131      timeout: 40000
132    }).done( function(msg){
133      if (msg.trim() == 'OK') {
134        this_form.find('.loading').slideUp();
135        this_form.find('.sent-message').slideDown();
136        this_form.find("input:not(input[type=submit]), textarea").val('');
137      } else {
138        this_form.find('.loading').slideUp();
139        if(!msg) {
140          msg = 'Form submission failed and no error message returned from: ' + action + '<br>';
141        }
142        this_form.find('.error-message').slideDown().html(msg);
143      }
144    }).fail( function(data){
145      console.log(data);
146      var error_msg = "Form submission failed!<br>";
147      if(data.statusText || data.status) {
148        error_msg += 'Status:';
149        if(data.statusText) {
150          error_msg += ' ' + data.statusText;
151        }
152        if(data.status) {
153          error_msg += ' ' + data.status;
154        }
155        error_msg += '<br>';
156      }
157      if(data.responseText) {
158        error_msg += data.responseText;
159      }
160      this_form.find('.loading').slideUp();
161      this_form.find('.error-message').slideDown().html(error_msg);
162    });
163  }
164
165})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.