1/** 2 * PHP Email Form Validation - v2.0 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 input, .form-group .select select, .form-group textarea'), 13 ferror = false, 14 emailExp = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i; 15 16 f.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 64 const vMessage = i.attr('data-msg') || 'Wrong Input'; 65 const vElement = i.closest('.form-group').find('.validate').first(); 66 vElement 67 .html((ierror ? vMessage : '')) 68 .show('blind'); 69 } 70 }); 71 72 $('.form-group input, select, textarea').on('input change', function () { 73 const i = $(this); 74 const vElement = i.closest('.form-group').find('.validate').first(); 75 76 if (this.checkValidity()) { 77 vElement.html('').hide(); 78 } 79 }); 80 81 if (ferror) return false; 82 83 var this_form = $(this); 84 var action = $(this).attr('action'); 85 86 if( ! action ) { 87 this_form.find('.loading').slideUp(); 88 this_form.find('.error-message').slideDown().html('The form action property is not set!'); 89 return false; 90 } 91 92 this_form.find('.sent-message').slideUp(); 93 this_form.find('.error-message').slideUp(); 94 this_form.find('.loading').slideDown(); 95 96 if ( $(this).data('recaptcha-site-key') ) { 97 var recaptcha_site_key = $(this).data('recaptcha-site-key'); 98 grecaptcha.ready(function() { 99 grecaptcha.execute(recaptcha_site_key, {action: 'php_email_form_submit'}).then(function(token) { 100 php_email_form_submit(this_form,action,this_form.serialize() + '&recaptcha-response=' + token); 101 }); 102 }); 103 } else { 104 php_email_form_submit(this_form,action,this_form.serialize()); 105 } 106 107 return true; 108 }); 109 110 function php_email_form_submit(this_form, action, data) { 111 $.ajax({
112 type: "POST", 113 url: action, 114 data: data, 115 timeout: 40000 116 }).done( function(msg){ 117 if (msg == 'OK') { 118 this_form.find('.loading').slideUp(); 119 this_form.find('.sent-message').slideDown(); 120 this_form.find("input:not(input[type=submit]), textarea").val(''); 121 this_form.trigger('form-reset-success'); 122 } else { 123 this_form.find('.loading').slideUp(); 124 if(!msg) { 125 msg = 'Form submission failed and no error message returned from: ' + action + '<br>'; 126 } 127 this_form.find('.error-message').slideDown().html(msg); 128 } 129 }).fail( function(data){ 130 console.log(data); 131 var error_msg = "Form submission failed!<br>"; 132 if(data.statusText || data.status) { 133 error_msg += 'Status:'; 134 if(data.statusText) { 135 error_msg += ' ' + data.statusText; 136 } 137 if(data.status) { 138 error_msg += ' ' + data.status; 139 } 140 error_msg += '<br>'; 141 } 142 if(data.responseText) { 143 error_msg += data.responseText; 144 } 145 this_form.find('.loading').slideUp(); 146 this_form.find('.error-message').slideDown().html(error_msg); 147 }); 148 } 149 150})(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.