1/* 2 *** This function is to get all the messages related to contact form 3 You need to pass form id and message key and this function will return contact form message. 4 *** Since: 1.3.0 5 *** @params: 6 1) form id 7 2) message key 8 *** return: Contact form message 9 */ 10function getContactFormMessage(formid,key){ 11 if(contactform == ""){ 12 return ""; 13 } 14 else{ 15 for (var i=0; i<contactform.length; i++){ 16 var checkId = contactform[i][0]; 17 var checkKey = contactform[i][1]; 18 var returnMsg = contactform[i][2]; 19 20 if(formid == checkId && checkKey == key){ 21 return returnMsg; 22 break; 23 } 24 } 25 } 26} 27 28// Default validator function 29function contactFormDefaultValidator(objForm){ 30 31 var formid=jQuery(objForm).find(".formid").val(); 32 var havingError = false; 33 34 // Fetch each validation field one by one 35 objForm.find('.wpcf7-validates-as-required').each(function(){ 36 jQuery(this).parent().find('.wpcf7-not-valid-tip').remove(); 37 // Check if empty or checkbox checked or not 38 if(!jQuery(this).hasClass('wpcf7-checkbox')){ 39 // For GDPR 40 if(jQuery(this).hasClass('wpcf7-wpgdprc')){ 41 var checkselected = 0; 42 jQuery(this).find('input').each(function(){ 43 if(jQuery(this).prop('checked') == true){ 44 checkselected++; 45 } 46 }); 47 if(checkselected == 0){ 48 jQuery(this).parent().find('.wpcf7-not-valid-tip').remove(); 49 jQuery(this).after('<span class="wpcf7-not-valid-tip" role="alert">'+getContactFormMessage(formid,'gdpr')+'</span>'); 50 havingError = true; 51 } 52 } 53 else if(!jQuery(this).val()){ 54 jQuery(this).val(''); 55 jQuery(this).parent().find('.wpcf7-not-valid-tip').remove(); 56 jQuery(this).after('<span class="wpcf7-not-valid-tip" role="alert">'+getContactFormMessage(formid,'invalid_required')+'</span>'); 57 havingError = true; 58 } 59 // Check if not valid email address entered 60 else{ 61 if(jQuery(this).attr('class').indexOf("wpcf7-validates-as-email") >= 0){ 62 var emailField = jQuery(this).val(); 63 if(!validateCustomFormEmail(emailField)){ 64 jQuery(this).parent().find('.wpcf7-not-valid-tip').remove(); 65 jQuery(this).after('<span role="alert" class="wpcf7-not-valid-tip">'+getContactFormMessage(formid,'invalid_email')+'</span>'); 66 havingError = true; 67 } 68 } 69 // Check if not valid url entered 70 else if(jQuery(this).attr('class').indexOf("wpcf7-validates-as-url") >= 0){ 71 var urlField = jQuery(this).val(); 72 if(!validateCustomFormurl(urlField)){ 73 jQuery(this).parent().find('.wpcf7-not-valid-tip').remove(); 74 jQuery(this).after('<span role="alert" class="wpcf7-not-valid-tip">'+getContactFormMessage(formid,'invalid_url')+'</span>'); 75 havingError = true; 76 } 77 } 78 // Check if not valid telephone entered 79 else if(jQuery(this).attr('class').indexOf("wpcf7-validates-as-tel") >= 0){ 80 var telField = jQuery(this).val(); 81 if(!validateCustomFormtel(telField)){ 82 jQuery(this).parent().find('.wpcf7-not-valid-tip').remove(); 83 jQuery(this).after('<span role="alert" class="wpcf7-not-valid-tip">'+getContactFormMessage(formid,'invalid_tel')+'</span>'); 84 havingError = true; 85 } 86 } 87 // Check if not valid number entered 88 else if(jQuery(this).attr('class').indexOf("wpcf7-validates-as-number") >= 0){ 89 var numField = jQuery(this).val(); 90 var min = jQuery(this).attr('min'); 91 var max = jQuery(this).attr('max'); 92 var testnum = validateCustomFormnum(numField,min,max); 93 if(testnum != 0){ 94 jQuery(this).parent().find('.wpcf7-not-valid-tip').remove(); 95 if(testnum ==1){ 96 jQuery(this).after('<span role="alert" class="wpcf7-not-valid-tip">'+getContactFormMessage(formid,'invalid_number')+'</span>'); 97 } 98 if(testnum ==2){ 99 jQuery(this).after('<span role="alert" class="wpcf7-not-valid-tip">'+getContactFormMessage(formid,'invalid_too_long')+'</span>'); 100 } 101 if(testnum ==3){ 102 jQuery(this).after('<span role="alert" class="wpcf7-not-valid-tip">'+getContactFormMessage(formid,'invalid_too_short')+'</span>'); 103 } 104 havingError = true; 105 } 106 } 107 // Check if not valid date entered 108 else if(jQuery(this).attr('class').indexOf("wpcf7-validates-as-date") >= 0){ 109 var date = jQuery(this).val(); 110 if(!validateCustomFordate(date)){ 111 jQuery(this).parent().find('.wpcf7-not-valid-tip').remove(); 112 jQuery(this).after('<span role="alert" class="wpcf7-not-valid-tip">'+getContactFormMessage(formid,'invalid_date')+'</span>'); 113 havingError = true; 114 } 115 } 116 } 117 } 118 else{ 119 var checkselected = 0; 120 jQuery(this).find('input').each(function(){ 121 if(jQuery(this).prop('checked') == true){ 122 checkselected++; 123 } 124 }); 125 if(checkselected == 0){ 126 jQuery(this).parent().find('.wpcf7-not-valid-tip').remove(); 127 jQuery(this).after('<span class="wpcf7-not-valid-tip" role="alert">'+getContactFormMessage(formid,'invalid_required')+'</span>'); 128 havingError = true; 129 } 130 } 131 }); 132 //for acceptance validation 133 if(jQuery(objForm).find('.wpcf7-acceptance').length > 0){ 134 if(jQuery(objForm).find('.wpcf7-acceptance').hasClass('wpcf7-invert')){ 135 if(jQuery(objForm).find('.wpcf7-acceptance').prop('checked') == true){ 136 jQuery(objForm).find('.wpcf7-acceptance').parent().find('.wpcf7-not-valid-tip').remove(); 137 jQuery(objForm).find('.wpcf7-acceptance').after('<span class="wpcf7-not-valid-tip" role="alert">'+getContactFormMessage(formid,'accept_terms')+'</span>'); 138 havingError = true; 139 } 140 else{ 141 jQuery(objForm).find('.wpcf7-acceptance').parent().find('.wpcf7-not-valid-tip').remove(); 142 } 143 } 144 else{ 145 if(jQuery(objForm).find('.wpcf7-acceptance').prop('checked') == false){ 146 jQuery(objForm).find('.wpcf7-acceptance').parent().find('.wpcf7-not-valid-tip').remove(); 147 jQuery(objForm).find('.wpcf7-acceptance').after('<span class="wpcf7-not-valid-tip" role="alert">'+getContactFormMessage(formid,'accept_terms')+'</span>'); 148 havingError = true; 149 } 150 else{ 151 jQuery(objForm).find('.wpcf7-acceptance').parent().find('.wpcf7-not-valid-tip').remove(); 152 } 153 } 154 } 155 156 return havingError; 157} 158//email validation function 159function validateCustomFormEmail(email) { 160 var expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,10}|[0-9]{1,3})(\]?)$/; 161 return expr.test(email); 162} 163//url validation function 164function validateCustomFormurl(url) { 165 if(url){ 166 return true; 167 } 168 else{ 169 return false; 170 } 171} 172//telephone validation function 173function validateCustomFormtel(number){
174 var phoneno = /[a-zA-Z]/; 175 if(number.match(phoneno)) { 176 return false; 177 } 178 else { 179 return true; 180 } 181} 182//number filed validation function 183function validateCustomFormnum(number,min,max){ 184 if (isNaN(number) ) { 185 return 1; 186 } 187 else { 188 if(min){ 189 if(number < min){ 190 return 3; 191 } 192 } 193 if(max){ 194 if(number > max){ 195 return 2; 196 } 197 } 198 return 0; 199 } 200} 201//date filed validation function 202function validateCustomFordate(input) { 203 var status = false; 204 if (!input || input.length <= 0) { 205 status = false; 206 } 207 else { 208 var result = new Date(input); 209 if (result == 'Invalid Date') { 210 status = false; 211 } 212 else { 213 status = true; 214 } 215 } 216 return status; 217}
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.