1/* 2 * @licstart The following is the entire license notice for the 3 * JavaScript code in this page. 4 * 5 * Copyright (c) 2007-2012 Oliver Seidel (email : oliver.seidel @ deliciousdays.com) 6 * Copyright (c) 2014-2017 Bastian Germann 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 * 21 * @licend The above is the entire license notice 22 * for the JavaScript code in this page. 23 */ 24 25function clearField(thefield) { 26 if (thefield.defaultValue == thefield.value) 27 thefield.value = ''; 28} 29 30function setField(thefield) { 31 if (thefield.value == '') 32 thefield.value = thefield.defaultValue; 33} 34 35 36function cforms_validate(no, directFormSubmission) { 37 38 var doInnerXHTML = function (elementId, stringXHTML) { 39 40 try { 41 if (document.getElementById(elementId + 'a')) 42 document.getElementById(elementId + 'a').innerHTML = stringXHTML; 43 if (document.getElementById(elementId + 'b')) 44 document.getElementById(elementId + 'b').innerHTML = stringXHTML; 45 return true; 46 } catch (ee) { 47 return false; 48 } 49 50 }; 51 52 var stripslashes = function (str) { 53 str = str.replace(/\\'/g, '\''); 54 str = str.replace(/\\"/g, '"'); 55 str = str.replace(/\\\\/g, '\\'); 56 str = str.replace(/\\0/g, '\0'); 57 return str; 58 }; 59 60 var set_customerr = function (id, parent_el) { 61 var gotone = all_custom_error[id]; 62 if (all_custom_error[id] && gotone != '') { 63 64 if (show_err_ins === 'y') { 65 insert_err_p[insert_err_count] = parent_el.id; 66 67 var ul = document.createElement('UL'); 68 var li = document.createElement('LI'); 69 li.innerHTML = stripslashes(gotone); 70 71 ul.appendChild(li); 72 ul.setAttribute('class', 'cf_li_text_err'); 73 74 insert_err[insert_err_count++] = ul; 75 } 76 77 if (parent_el.id != '') 78 return custom_error + '<li><a href="#' + parent_el.id + '">' + gotone + ' »</li></a>'; 79 else 80 return custom_error + '<li>' + gotone + '</li>'; 81 82 } else 83 return custom_error; 84 }; 85 86 // track and store all errors until end 87 var check_for_customerr = function (id) { 88 89 var parent_el = document.getElementById(id).parentNode; 90 parent_el.className = "cf_li_err"; 91 92 return set_customerr(id, parent_el); 93 }; 94 95 var check_for_customerr_radio = function (id, cerr) { 96 var parent_el = document.getElementById(id.substr(0, id.length - 5)); 97 parent_el.className = "cf-box-title cf_li_err"; 98 99 return set_customerr(cerr, parent_el); 100 }; 101 102 var isParentChkBoxGroup = function (el) { 103 while (el.parentNode) { 104 if (el.parentNode.className === 'cf-box-group') 105 return true; 106 else 107 el = el.parentNode; 108 } 109 return false; 110 }; 111 112 var cforms_submitform = function (no) { 113 var regexp = new RegExp('[$][#][$]', ['g']); 114 var prefix = '\n'; 115 116 var params = ''; 117 118 var objColl = document.getElementById('cforms' + no + 'form').getElementsByTagName('*'); 119 120 for (var i = 0, j = objColl.length; i < j; i++) { 121 122 var fld = objColl[i].nodeName.toLowerCase(); 123 var typ = objColl[i].type; 124 125 if (fld == "input" || fld == "textarea" || fld == "select") { 126 127 if (typ == "checkbox") { 128 129 if (objColl[i].name.match(/\[\]/)) { 130 var group = ''; 131 132 while (i < j && isParentChkBoxGroup(objColl[i])) { 133 if (objColl[i].type == 'checkbox' && objColl[i].name.match(/\[\]/) && objColl[i].checked) { 134 group = group + objColl[i].value + ','; 135 } 136 i++; 137 } 138 139 if (group.length > 1) 140 params = params + prefix + group.substring(0, group.length - 1); 141 else 142 params = params + prefix + ""; 143 } else 144 params = params + prefix + (objColl[i].checked ? ((objColl[i].value != "") ? objColl[i].value : "X") : ""); 145 146 } else if (typ == "radio") { 147 148 var group = objColl[i].checked ? ((objColl[i].value != "") ? objColl[i].value : "X") : ''; 149 150 while (i < j && isParentChkBoxGroup(objColl[i + 1])) { 151 152 if (objColl[i + 1].type == 'radio' && objColl[i + 1].checked) { 153 group = group + ',' + objColl[i + 1].value; 154 } 155 156 i++; 157 } 158 if (group.charAt(0) == ',') 159 params = params + prefix + group.substring(1, group.length); 160 else 161 params = params + prefix + group; 162 163 164 } else if (typ == "select-multiple") { 165 var all_child_obj = ''; 166 for (var z = 0; z < objColl[i].childNodes.length; z++) { 167 if (objColl[i].childNodes[z].nodeName.toLowerCase() == 'option' && objColl[i].childNodes[z].selected) { 168 all_child_obj = all_child_obj + objColl[i].childNodes[z].value.replace(regexp, '$') + ','; 169 } 170 } 171 params = params + prefix + all_child_obj.substring(0, all_child_obj.length - 1); 172 } else if (typ == "hidden" && objColl[i].className.match(/cfhidden/)) { 173 params = params + prefix + objColl[i].value; 174 } else if (typ != "hidden" && typ != "submit") { 175 params = params + prefix + objColl[i].value.replace(regexp, '$'); 176 } 177 } 178 } 179 180 // Overwrite params with generic form 181 params = jQuery('#cforms' + no + 'form').serialize(); 182 var post_data = 'action=submitcform&_wpnonce=' 183 + cforms2_ajax.nonces['submitcform'] 184 + '&cforms_id=' + no + '&' + params; 185 jQuery.post( 186 cforms2_ajax.url, 187 post_data, 188 function (data) { 189 cforms_setsuccessmessage(data); 190 } 191 ); 192 }; 193 194 var cforms_setsuccessmessage = function (message) { 195 196 var no = message.no; 197 198 if (!message.result.match(/success/)) { 199 call_err(no, message.html, ''); 200 return; 201 } 202 if (!document.getElementById('cforms' + no + 'form').className.match(/cfnoreset/)) 203 document.getElementById('cforms' + no + 'form').reset(); 204 205 document.getElementById('sendbutton' + no).style.cursor = "auto"; 206 document.getElementById('sendbutton' + no).disabled = false;
207 208 if (document.createEvent) { 209 var event = document.createEvent("HTMLEvents"); 210 event.initEvent("cforms2FormSent", true, true); 211 event.eventName = "cforms2FormSent"; 212 event.formNumber = no; 213 document.body.dispatchEvent(event); 214 } 215 216 var stringXHTML = message.html; 217 218 // for both message boxes 219 var isA = false; 220 var ucm = (parseInt(no) > 1) ? ' ' + message.result + no : ''; 221 if (document.getElementById('usermessage' + no + 'a')) { 222 document.getElementById('usermessage' + no + 'a').className = "cf_info " + message.result + ucm; 223 isA = true; 224 } 225 if (document.getElementById('usermessage' + no + 'b') && !(message.hide && isA)) { 226 document.getElementById('usermessage' + no + 'b').className = "cf_info " + message.result + ucm; 227 } 228 229 doInnerXHTML('usermessage' + no, stringXHTML); 230 231 if (message.hide) { 232 document.getElementById('cforms' + no + 'form').style.display = 'none'; 233 if (!message.redirection) 234 location.hash = '#usermessage' + no + 'a'; 235 } 236 237 if (message.redirection) { 238 location.href = message.redirection; 239 } 240 }; 241 242 var write_customerr = function () { 243 for (var n = 0; n < insert_err_p.length; n++) { 244 if (document.getElementById(insert_err_p[n])) { 245 document.getElementById(insert_err_p[n]).insertBefore( 246 insert_err[n], 247 document.getElementById(insert_err_p[n]).firstChild 248 ); 249 } 250 } 251 }; 252 253 if (!no) 254 no = ''; 255 256 var msgbox = 'usermessage' + no; 257 if (document.getElementById(msgbox + 'a')) { 258 document.getElementById(msgbox + 'a').className = "cf_info waiting"; 259 } 260 if (document.getElementById(msgbox + 'b')) { 261 document.getElementById(msgbox + 'b').className = "cf_info waiting"; 262 } 263 264 var waiting = decodeURI(document.getElementById('cf_working' + no).value); 265 waiting = waiting.replace(/\\/g, ""); 266 267 var insert_err = []; 268 var insert_err_p = []; 269 var insert_err_count = 0; 270 271 var all_custom_error = []; 272 273 var customerr_concatenated = document.getElementById('cf_customerr' + no).value; 274 var show_err_ins = customerr_concatenated.substr(0, 1); 275 276 var error_container = decodeURIComponent(customerr_concatenated.substr(1)).split('|'); 277 278 for (var i = 0; i < error_container.length; i++) { 279 var keyvalue = error_container[i].split('$#$'); 280 all_custom_error[keyvalue[0]] = keyvalue[1]; 281 } 282 283 var custom_error = ''; 284 285 286 if (!doInnerXHTML(msgbox, waiting)) { 287 return true; 288 } 289 290 var all_valid = true; 291 292 var regexp_e = new RegExp('^[_a-z0-9+-]+(\\.[_a-z0-9+-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,63})$', 'i'); // email regexp 293 294 295 // clean enhanced error if present 296 var objColl = document.getElementById('cforms' + no + 'form').getElementsByTagName('li'); 297 for (var i = 0; i < objColl.length; i++) { 298 if (objColl[i].className.match(/cf_li_err/)) { 299 if (objColl[i].className.match(/cf-box-title/)) 300 objColl[i].className = 'cf-box-title'; 301 else 302 objColl[i].className = ''; 303 } 304 } 305 306 objColl = document.getElementById('cforms' + no + 'form').getElementsByTagName('ul'); 307 while (objColl.length > 0) { 308 objColl[0].parentNode.removeChild(objColl[0]); 309 } 310 311 312 objColl = document.getElementById('cforms' + no + 'form').getElementsByTagName('*'); 313 var last_one = false; 314 315 for (var i = 0, j = objColl.length; i < j; i++) { 316 317 var temp = objColl[i].className; 318 319 var newclass = ''; 320 if (temp.match(/secinput/)) 321 newclass = 'secinput'; 322 else if (temp.match(/cf-box-./)) 323 newclass = temp.match(/cf-box-./); 324 else if (temp.match(/cformselect/)) 325 newclass = 'cformselect'; 326 else if (temp.match(/upload/)) 327 newclass = 'cf_upload'; 328 else if (temp.match(/single/)) 329 newclass = 'single'; 330 else if (temp.match(/area/)) 331 newclass = 'area'; 332 else if (temp.match(/cfselectmulti/)) 333 newclass = 'cfselectmulti'; 334 335 var fld = objColl[i].nodeName.toLowerCase(); 336 var typ = objColl[i].type; 337 338 if ((fld == "input" || fld == "textarea" || fld == "select") && !(typ == "hidden" || typ == "submit")) { 339 340 if (temp.match(/required/) && !temp.match(/email/) && typ != "radio") { 341 342 newclass = newclass + ' fldrequired'; 343 344 var n = objColl[i].nextSibling; 345 var p = objColl[i].previousSibling; 346 347 if (temp.match(/cf-box-./)) { 348 349 if (!objColl[i].checked) { 350 351 custom_error = check_for_customerr(objColl[i].id); 352 353 newclass = newclass + ' cf_error'; 354 355 // we can't change the checkbox much but the text on the side! 356 if (n && n.nodeName.toLowerCase() == "label" && !n.className.match(/errortxt/)) 357 n.className = n.className + " cf_errortxt"; 358 else if (p && p.nodeName.toLowerCase() == "label" && !p.className.match(/errortxt/)) 359 p.className = p.className + " cf_errortxt"; 360 361 362 all_valid = false;
363 if (!last_one && objColl[i].id != '') 364 last_one = objColl[i].id; 365 } else { 366 // we can't change the checkbox much but the text on the side! 367 if (n && n.nodeName.toLowerCase() == "label" && n.className.match(/cf_errortxt/)) 368 n.className = n.className.substr(0, n.className.search(/ cf_errortxt/)); 369 else if (p && p.nodeName.toLowerCase() == "label" && p.className.match(/cf_errortxt/)) 370 p.className = p.className.substr(0, p.className.search(/ cf_errortxt/)); 371 } 372 373 374 } else if (temp.match(/cformselect/)) { 375 376 if (objColl[i].value == '' || objColl[i].value == '-') { 377 newclass = newclass + ' cf_error'; 378 all_valid = false; 379 if (!last_one && objColl[i].id != '') 380 last_one = objColl[i].id; 381 382 custom_error = check_for_customerr(objColl[i].id); 383 384 } 385 386 } else if (objColl[i].value == '') { 387 388 newclass = newclass + ' cf_error'; 389 all_valid = false; 390 if (!last_one && objColl[i].id != '') 391 last_one = objColl[i].id; 392 393 custom_error = check_for_customerr(objColl[i].id); 394 395 } 396 397 } 398 399 if (temp.match(/email/)) { 400 newclass = newclass + ' fldemail'; 401 if (!(objColl[i].value == '' && !temp.match(/required/))) { 402 if (!regexp_e.test(objColl[i].value)) { 403 newclass = newclass + ' fldrequired cf_error'; 404 all_valid = false; 405 if (!last_one) 406 last_one = objColl[i].name; 407 408 custom_error = check_for_customerr(objColl[i].id); 409 410 } else 411 newclass = newclass + ' fldrequired'; 412 } 413 414 } 415 416 if (temp.match(/required/) && temp.match(/cf-box-b/) && typ.match(/radio/)) { 417 var temp_i = i; 418 var radio_valid = false; 419 420 while (objColl[i].parentNode.className.match(/cf-box-group/) 421 || objColl[i].parentNode.parentNode.className.match(/cf-box-group/)) { 422 temp = objColl[i].className; 423 if (temp.match(/cf-box-b/) && objColl[i].checked) { 424 radio_valid = true; 425 } 426 i++; 427 } 428 429 if (!radio_valid) { 430 all_valid = false; 431 if (!last_one) 432 last_one = objColl[temp_i].parentNode.id; 433 custom_error = check_for_customerr_radio( 434 objColl[temp_i].parentNode.id, 435 objColl[temp_i].id.substr(0, objColl[temp_i].id.length - 2) 436 ); 437 } 438 } else 439 objColl[i].className = newclass; 440 441 442 } 443 444 445 // if regexp provided use it! 446 var regexp = 1; 447 if (objColl[i] && document.getElementById(objColl[i].id + '_regexp')) { 448 449 var obj_regexp = document.getElementById(objColl[i].id + '_regexp'); 450 var inpVal = objColl[i].value; 451 if (typ == 'textarea') 452 inpVal = inpVal.replace(/\n\r?/g, ' '); 453 454 if (obj_regexp && obj_regexp.value != '') { 455 456 if (document.getElementById(obj_regexp.value)) { 457 if (inpVal != document.getElementById(obj_regexp.value).value) 458 regexp = null; 459 } else { 460 if (inpVal != '') { // overrule: normal field, normal regexp, left empty 461 regexp = new RegExp(obj_regexp.value, ['g']); 462 regexp = inpVal.match(regexp); 463 } 464 } 465 466 if (regexp == null) { 467 newclass = newclass + ' cf_error'; 468 all_valid = false;
469 if (!last_one && objColl[i].id != '') 470 last_one = objColl[i].id; 471 custom_error = check_for_customerr(objColl[i].id); 472 } 473 474 } 475 } 476 477 478 } 479 480 // write out all custom errors 481 if (show_err_ins === 'y') 482 write_customerr(); 483 484 if (all_valid) { 485 document.getElementById('sendbutton' + no).style.cursor = "progress"; 486 if (directFormSubmission) { 487 return true; 488 } else { 489 document.getElementById('sendbutton' + no).disabled = true; 490 cforms_submitform(no); 491 } 492 } 493 494 var call_err = function (no, err, custom_error) { 495 496 // temp. turn send button back on 497 document.getElementById('sendbutton' + no).style.cursor = "auto"; 498 document.getElementById('sendbutton' + no).disabled = false; 499 500 if (custom_error != '') 501 custom_error = '<ol>' + custom_error + '</ol>'; 502 503 err = decodeURI(err) + custom_error; 504 505 var stringXHTML = err.replace(/(\r\n)/g, '<br />'); 506 507 var msgbox = 'usermessage' + no; 508 var ucm = (parseInt(no) > 1) ? ' failure' + no : ''; 509 510 if (document.getElementById(msgbox + 'a')) 511 document.getElementById(msgbox + 'a').className = "cf_info failure" + ucm; 512 if (document.getElementById(msgbox + 'b')) 513 document.getElementById(msgbox + 'b').className = "cf_info failure" + ucm; 514 515 doInnerXHTML(msgbox, stringXHTML.replace(/\\/g, "")); 516 }; 517 518 if (!all_valid) { 519 call_err(no, document.getElementById('cf_failure' + no).value, custom_error); 520 } 521 522 return false; 523 524} 525 526jQuery(function () { 527 jQuery('form.cform[id^="cforms"][id$="form"]').submit(function (ev) { 528 var id = jQuery(ev.target).attr('id'); 529 var no = /^cforms(\d*)form$/.exec(id)[1]; 530 var direct = jQuery(ev.target).hasClass('cformsdirect'); 531 return cforms_validate(no, direct); 532 }); 533});
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.