1/** 2 * ======================================= 3 * Frontend submit form check 4 * ======================================= 5 * */ 6(function($) { 7 "use strict"; 8 $.ProRadioBtoolsSubmit = { 9 errors: { 10 missing : 'Error: the field is missing, incorrect or too short', 11 link : 'Error: invalid URL format', 12 phone : 'Error: incorrect phone number', 13 email : 'Error: incorrect email address', 14 dateFormat : 'Error: wrong date format', 15 check : 'Please read carefully and agree with the term', 16 formerror: 'Some fields are not correctly compiled, please check before proceeding.', 17 }, 18 fn: { 19 doValid: function(sel){ 20 $(sel).addClass('prbt-valid'); 21 }, 22 doError: function(sel, e){ 23 $(sel).addClass('prbt-invalid'); 24 $(sel).after('<p class="prbt-error-form">'+e+'</p>'); 25 }, 26 validateDate: function(testdate) { 27 var date_regex = /^\d{4}\-(0?[1-9]|1[012])\-(0?[1-9]|[12][0-9]|3[01])$/ ; 28 return date_regex.test(testdate); 29 }, 30 isUrlValid: function(url) { 31 return /^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(url); 32 }, 33 isPhoneValid: function(input) { 34 return /\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/.test(input); 35 }, 36 isEmailValid: function(input) { 37 // return /^\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$/.test(input); 38 var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; 39 return regex.test(input); 40 }, 41 validateForm: function(that, form){ 42 var errors = 0; 43 44 $('.prbt-error-form').remove(); 45 form.find('.prbt-valid').removeClass('prbt-valid'); 46 form.find('.prbt-invalid').removeClass('prbt-invalid'); 47 48 49 // Title check 50 if($('#prbt-title').val() === '' || $('#prbt-title').val().length < 5 ){ 51 that.fn.doError( '#prbt-title', that.errors.missing ); 52 errors ++; 53 } else { 54 that.fn.doValid( '#prbt-title' ); 55 } 56 // Date check 57 if( !that.fn.validateDate($('#prbt-start_date').val()) ){ 58 that.fn.doError( '#prbt-start_date', that.errors.dateFormat ); 59 errors ++; 60 } else { 61 that.fn.doValid( '#prbt-start_date' ); 62 } 63 // Date check 64 if( !that.fn.validateDate($('#prbt-end_date').val()) ){ 65 that.fn.doError( '#prbt-end_date', that.errors.dateFormat ); 66 errors ++; 67 } else { 68 that.fn.doValid( '#prbt-end_date' ); 69 } 70 // Link check 71 if( !that.fn.isUrlValid($('#prbt-link').val()) ){ 72 that.fn.doError( '#prbt-link', that.errors.link ); 73 errors ++; 74 } else { 75 that.fn.doValid( '#prbt-link' ); 76 } 77 78 // Phone check 79 if( !that.fn.isPhoneValid($('#prbt-phone').val()) ){ 80 that.fn.doError( '#prbt-phone', that.errors.phone ); 81 errors ++; 82 } else { 83 that.fn.doValid( '#prbt-phone' ); 84 } 85 86 // Email check 87 if( !that.fn.isEmailValid($('#prbt-email').val()) ){ 88 that.fn.doError( '#prbt-email', that.errors.email ); 89 errors ++; 90 } else { 91 that.fn.doValid( '#prbt-email' ); 92 } 93 94 // antispam check 95 if( $('#prbt-as').val() != $('#prbt-as').data('prbt-ctrl') ) { 96 that.fn.doError( '#prbt-as', that.errors.missing ); 97 errors ++; 98 } else { 99 that.fn.doValid( '#prbt-as' ); 100 } 101 102 103 // checkbox check 104 if( !$('#prbt-check').is(":checked") ) { 105 that.fn.doError( '#prbt-check', that.errors.check ); 106 errors ++; 107 } else { 108 that.fn.doValid( '#prbt-check' ); 109 } 110 if( !$('#prbt-verified').is(":checked") ) { 111 that.fn.doError( '#prbt-verified', that.errors.check ); 112 errors ++; 113 } else { 114 that.fn.doValid( '#prbt-verified' ); 115 }
116 if(0 === errors){ 117 return true; 118 } else { 119 $('html, body').animate({ 120 scrollTop: form.offset().top - 100 121 }, 500); 122 that.fn.doError( '#prbt-submitbutton', that.errors.formerror ); 123 } 124 125 }, 126 init: function( that ) { 127 var form = $('#prbt-frontend-form'); 128 var isValid = false; 129 $('#prbt-preflight').on('click', function(e){ 130 e.preventDefault(); 131 isValid = that.fn.validateForm(that, form); 132 if( isValid ){ 133 $('#prbt-preflight').hide(); 134 $( '#prbt-submitbutton').show().removeAttr("disabled"); 135 form.on('submit',function(e){ 136 137 isValid = that.fn.validateForm(that, form); 138 if(!isValid){ 139 e.preventDefault(); 140 return false; 141 } 142 }); 143 } 144 }); 145 146 $('#prbt-frontend-form :input').change(function() { 147 $('#prbt-preflight').show(); 148 $( '#prbt-submitbutton').hide().attr("disabled",true); 149 }); 150 151 }, 152 } 153 } 154 155 jQuery(document).ready(function() { 156 $.ProRadioBtoolsSubmit.fn.init( $.ProRadioBtoolsSubmit ); 157 }); 158})(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.