PageSourceSearch

https://www.csgtalent.com/scripts/test_formvalidation.js

js csgtalent.com collected 2026-09-30 09:59:41 UTC 18,448 bytes, 490 lines download raw bytes

1
2// CACHED HIT START (RAM) at 09/30/2026 09:59:41
3var DATADOWNLOADFORMSESSION = "DownloadFormSession";
4
5function validApteveForms() {
6  $(document).on('click', '.apteveForm [type="submit"]', function(e) {
7    e.preventDefault();
8    var isValid = true;
9    var this_btn = $(this);
10
11
12    var closestform = '#' + $(this).closest('form').attr('id');
13    this_btn.hide();
14    $('.element.submit', closestform).append('<button type="submit" class="btn spinnerbtn" disabled="disabled">\
15                                                    <i class="fas fa-spinner fa-spin"></i>\
16                                                </button>')
17
18    var data_capture_download = "";
19    var ccEmail = $('#media-hub-download-form').closest('.form-holder').find('[data-consultantemailcc]').attr('data-consultantemailcc');
20    if ($(closestform).closest('.form-holder').find('[data-download]').length > 0) {
21      data_capture_download = $(closestform).closest('.form-holder').find('[data-download]').attr('data-download');
22      if (data_capture_download.indexOf('.') < 0) //Decode
23      {
24        data_capture_download = atob(data_capture_download);
25      }
26    }
27
28    if (data_capture_download != "") {
29      sessionStorage.setItem(DATADOWNLOADFORMSESSION, data_capture_download)
30    }
31
32    if ($("[name='ApteveDestinationEmails']", closestform).length > 0) {
33      $("[name='ApteveDestinationEmails']", closestform).val(ccEmail)
34    }
35
36
37    if ($('select[name="guideoptions"]', closestform).length > 0) {
38      if ($('select[name="guideoptions"]', closestform).val() === "") {
39        $('select[name="guideoptions"]', closestform).closest('.form-group').find('.required-text').show()
40        isValid = false;
41      } else {
42        isValid = true;
43      }
44    }
45
46
47    $('input[type=text]', closestform).each(function() {
48      if ($(this).is(':visible')) {
49        if ($(this).attr('name') === "url") {
50          if ($(this).val() === "" && $(this).attr('data-req') === "Required") {
51            $(this).closest('.form-group').find('.required-text').show()
52            $(this).closest('.form-group').find('.required-linkeidn').hide()
53            $(this).closest('.form-group').find('.required-dropbox').hide()
54            is_valid = false;
55          } else if ($(this).val().indexOf("https://www.linkedin.com/") < 0) {
56            $(this).closest('.form-group').find('.required-linkeidn').show()
57            is_valid = false;
58          } else if ($(this).val().indexOf("https://www.dropbox.com/") < 0) {
59            $(this).closest('.form-group').find('.required-linkeidn').show()
60            is_valid = false;
61          } else {
62            $(this).closest('.form-group').find('.required-text').hide()
63            $(this).closest('.form-group').find('.required-linkedin').hide()
64          }
65        } else {
66          if ($(this).val() === "" && $(this).attr('data-req') === "Required") {
67            $(this).closest('.form-group').find('.required-text').show()
68            is_valid = false;
69          } else {
70            $(this).closest('.form-group').find('.required-text').hide()
71          }
72        }
73      }
74    })
75
76    $('textarea', closestform).each(function() {
77      if ($(this).is(':visible')) {
78        if ($(this).val() === "" && $(this).attr('data-req') === "Required") {
79          $(this).closest('.form-group').find('.required-text').show()
80          is_valid = false;
81        } else {
82          $(this).closest('.form-group').find('.required-text').hide()
83        }
84      }
85    })
86
87    $('input[type=email]', closestform).each(function() {
88      if ($(this).is(':visible')) {
89        if ($(this).val() === "" && $(this).attr('data-req') === "Required") {
90          $(this).closest('.form-group').find('.required-text').show();
91          $(this).closest('.form-group').find('.required-email').hide()
92        } else if (isValidEmailAddress($(this).val()) === false) {
93          $(this).closest('.form-group').find('.required-text').hide();
94          $(this).closest('.form-group').find('.required-email').show()
95          is_valid = false;
96        } else {
97          $(this).closest('.form-group').find('.required-text').hide()
98          $(this).closest('.form-group').find('.required-email').hide()
99        }
100      }
101    })
102
103    $('input[type="checkbox"]', closestform).each(function() {
104      if ($(this).attr('data-req') === "Required" && $(this).prop('checked') === false) {
105        $(this).closest('.form-group').find('.required-text').show()
106        is_valid = false;
107      } else {
108        $(this).closest('.form-group').find('.required-text').hide()
109      }
110    })
111
112    $('select', closestform).each(function() {
113      if ($(this).attr('data-req') === "Required") {
114        if ($(this).attr('data-isSelected') === 'false') {
115          $(this).closest('.form-group').find('.required-text').show()
116          is_valid = false;
117        } else {
118          $(this).closest('.form-group').find('.required-text').hide()
119        }
120      }
121    })
122
123    $('input[type="file"]', closestform).each(function() {
124      if ($(this).is(':visible')) {
125        var error_displayed = $(this).closest('.element').find('.error').is(':visible');
126        var error_displayed_class = $(this).closest('.element').find('.error:visible');
127        if (error_displayed_class.length > 0) {
128          error_displayed_class = error_displayed_class.attr('class').split(' ')[1];
129        }
130        if ($(this).attr('data-req') === "Required") {
131          if ($(this).attr('data-isFileValid') === "false" && error_displayed == false) {
132            $(this).closest('.element').find('.required-text').show()
133          } else if ($(this).attr('data-isFileValid') === "false" && error_displayed == true) {
134            $(this).closest('.element').find('.error').each(function() {
135              if ($(this).attr('class').indexOf('' + error_displayed_class + '') >= 0) {
136                $(this).show()
137              } else {
138                $(this).hide()
139              }
140            })
141          } else {
142            $(this).closest('.element').find('.error').each(function() {
143              $(this).hide()
144            })
145          }
146        }
147      }
148    })
149
150    addUTMSessionValues(closestform);
151
152    if ($('.error:visible', closestform).length > 0 || isValid === false) {
153      $('.spinnerbtn').remove();
154      this_btn.show();
155      return false;
156    } else {
157      updateForm(closestform.replace('#', ''), "https://cms.wearevennture.co.uk", $('input[name="formlink"]', $(closestform)).val());
158
159      if ($(closestform).attr('class').indexOf('interna') >= -1) {
160        sendForm($(this).closest('form').attr('id'));
161      } else {
162
163        if (typeof grecaptcha !== 'undefined') {
164          var captchaUrl = 'https://www.google.com/recaptcha/enterprise.js?render=',
165            $captchaScript = $("script[src*='" + captchaUrl + "']");
166          if ($captchaScript.length > 0) {
167            var captchaKey = $captchaScript.attr("src").substr(captchaUrl.length);
168            if (captchaKey) {
169              try {
170                grecaptcha.enterprise.execute(captchaKey, {
171                  action: 'submit'
172                }).then(function(token) {
173                  if ($(closestform).find("input[name='g-recaptcha-response']").length === 0) {
174                    $(closestform).append("<input type='hidden' name='g-recaptcha-response' value='" + token + "'>");
175                  } else {
176                    $(closestform).find("input[name='g-recaptcha-response']").val(token);
177                  }
178                  $(closestform).submit();
179                });
180                return;
181              } catch (error) {
182                console.error(error);
183                $(closestform).submit();
184              }
185            }
186          }
187        } else{
188          $(closestform).submit();
189        }
190      }
191
192      
193    }
194  });
195}
196validApteveForms();
197
198function addUTMSessionValues(closestform) {
199  if (sessionStorage.getItem('UTMSOURCESESSION') !== null) {
200    $('input[name="utm_source"]', closestform).val(sessionStorage.getItem('UTMSOURCESESSION'));
201  }
202
203  if (sessionStorage.getItem('UTMCAMPAIGNSESSION') !== null) {
204    $('input[name="utm_campaign"]', closestform).val(sessionStorage.getItem('UTMCAMPAIGNSESSION'));
205  }
206
207  if (sessionStorage.getItem('UTMMEDIUMSESSION') !== null) {
208    $('input[name="utm_medium"]', closestform).val(sessionStorage.getItem('UTMMEDIUMSESSION'));
209  }
210
211  if (sessionStorage.getItem('UTMCONTENTSESSION') !== null) {
212    $('input[name="utm_content"]', closestform).val(sessionStorage.getItem('UTMCONTENTSESSION'));
213  }
214
215  if (sessionStorage.getItem('GOOGLECLICKIDSESSION') !== null) {
216    $('input[name="gclid"]', closestform).val(sessionStorage.getItem('GOOGLECLICKIDSESSION'));
217  }
218
219  if (sessionStorage.getItem('ORIGINALUTMSOURCE') !== null) {
220    $('input[name="pagesource"]', closestform).val(sessionStorage.getItem('ORIGINALUTMSOURCE'));
221  }
222
223  if (sessionStorage.getItem('PAGESOURCESUBMISSION') !== null) {
224    $('input[name="submissionpagesource"]', closestform).val(sessionStorage.getItem('PAGESOURCESUBMISSION'));
225  }
226
227}
228
229function isValidEmailAddress(emailAddress) {
230  var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,10}$/i);
231  return pattern.test(emailAddress);
232}
233
234
235const isValidUrl = urlString => {
236  var urlPattern = new RegExp('^(https?:\\/\\/)?' + // validate protocol
237    '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // validate domain name
238    '((\\d{1,3}\\.){3}\\d{1,3}))' + // validate OR ip (v4) address
239    '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // validate port and path
240    '(\\?[;&a-z\\d%_.~+=-]*)?' + // validate query string
241    '(\\#[-a-z\\d_]*)?$', 'i'); // validate fragment locator
242  return !!urlPattern.test(urlString);
243}
244
245function formFileUpload() {
246  $('input[type="file"]').each(function() {
247    $(this).change(function(e) {
248      var files = e.originalEvent.target.files;
249      for (var i = 0, len = files.length; i < len; i++) {
250        var file = files[i].name;
251        if (file != null) {
252          var extension = file.substr((file.lastIndexOf('.') + 1));
253          switch (extension) {
254            case 'doc':
255            case 'pdf':
256            case 'docx':
257              flag = true;
258              break;
259            default:
260              flag = false;
261          }
262        } else {
263          return false;
264        }
265        var id = e.originalEvent.target.id;
266        if (flag == false) {
267          $(this).attr('data-isFileValid', "false");
268          if ($(this).closest('.file').find('.required-filetype').length > 0) {
269            $(this).closest('.file').find('.required-filesize').hide();
270            $(this).closest('.file').find('.required-text').hide();
271            $(this).closest('.file').find('.required-filetype').show();
272          } else {
273            $(this).closest('.file').find('.required-text').text('You can only upload doc, docx or pdf files').show();
274          }
275          return false;
276        } else {
277          var size = GetFileSize(files[i]);
278          if (size > 10) {
279            $(this).attr('data-isFileValid', "false");
280            if ($(this).closest('.file').find('.required-filesize').length > 0) {
281              $(this).closest('.file').find('.required-filesize').show();
282              $(this).closest('.file').find('.required-text').hide();
283              $(this).closest('.file').find('.required-filetype').hide();
284            } else {
285              $(this).closest('.file').find('.required-text').text('You can only upload files up to 10 MB in size').show();
286            }
287            return false;
288          } else {
289            $(this).closest('.file').find('.required-filesize').hide();
290            $(this).closest('.file').find('.required-text').hide();
291            $(this).closest('.file').find('.required-filetype').hide();
292            $(this).attr('data-isFileValid', "true");
293            return true;
294          }
295        }
296      }
297    })
298  })
299}
300formFileUpload();
301
302function GetFileSize(file) {
303  try {
304    var fileSize = 0;
305    fileSize = file.size //size in kb
306    fileSize = fileSize / 1048576; //size in mb
307    return fileSize;
308  } catch (e) {
309    alert("Error is :" + e);
310  }
311}
312
313function selectChange() {
314  $('.apteveForm select').each(function() {
315    $(this).on('change', function() {
316      var select_val = $(this).val();
317      if (select_val === "") {
318        $(this).attr('data-isSelected', "false");
319      } else {
320        $(this).attr('data-isSelected', "true");
321      }
322    })
323  })
324}
325selectChange();
326
327function downloadRedirect() {
328  var url = window.location.pathname;
329  var has_session_set = false;
330  if (sessionStorage.DownloadFormSession === undefined || sessionStorage.DownloadFormSession === "undefined") {
331    has_session_set = true;
332  } else if (sessionStorage.DownloadFormSession === '') {
333    has_session_set = true;
334  }
335
336  if (has_session_set === false) {
337    if (url.indexOf('thank-you') >= 0 || url.indexOf('thankyou') >= 0) {
338      let temp_url = sessionStorage.getItem(DATADOWNLOADFORMSESSION);
339      sessionStorage.setItem(DATADOWNLOADFORMSESSION, '');
340      window.open(temp_url, '_self');
341    }
342  }
343}
344downloadRedirect();
345
346function inputChangeApteveForms() {
347  $('.apteveForm input[type="text"]').each(function() {
348    $(this).on('input', function() {
349      if ($(this).val() === "" && $(this).attr('data-req') === "Required") {
350        $(this).closest('.form-group').find('.required-text').show()
351      } else {
352        $(this).closest('.form-group').find('.required-text').hide()
353      }
354    })
355  })
356
357  $('.apteveForm input[type="email"]').each(function() {
358    $(this).on('input', function() {
359      if ($(this).val() === "" && $(this).attr('data-req') === "Required") {
360        $(this).closest('.form-group').find('.required-text').show();
361        $(this).closest('.form-group').find('.required-email').hide()
362      } else if (isValidEmailAddress($(this).val()) === false) {
363        $(this).closest('.form-group').find('.required-text').hide();
364        $(this).closest('.form-group').find('.required-email').show()
365      } else {
366        $(this).closest('.form-group').find('.required-text').hide()
367        $(this).closest('.form-group').find('.required-email').hide()
368      }
369    })
370  })
371
372  $('.apteveForm input[type="checkbox"]').each(function() {
373    $(this).on('change', function() {
374      if ($(this).attr('data-req') === "Required" && $(this).prop('checked') === false) {
375        $(this).closest('.form-group').find('.required-text').show()
376      } else {
377        $(this).closest('.form-group').find('.required-text').hide()
378      }
379    })
380  })
381
382  $('.apteveForm select').each(function() {
383    $(this).on('change', function() {
384      if ($(this).attr('data-req') === "Required") {
385        var select_val = $(this).val();
386        if (select_val === "") {
387          $(this).attr('data-isSelected', "false");
388          $(this).closest('.form-group').find('.required-text').show()
389        } else {
390          $(this).attr('data-isSelected', "true");
391          $(this).closest('.form-group').find('.required-text').hide()
392        }
393      }
394    })
395  })
396
397  $('.apteveForm textarea').each(function() {
398    $(this).on('input', function() {
399      if ($(this).attr('data-req') === "Required" && $(this).val() === "") {
400        $(this).closest('.form-group').find('.required-text').show()
401      } else {
402        $(this).closest('.form-group').find('.required-text').hide()
403      }
404    })
405  })
406}
407
408function sendForm(formID) {
409  var $form = $('#' + formID);
410  var form_url = $form.attr('action');
411  var isCmsForm= form_url === "https://cms.wearevennture.co.uk/form/submit/";
412  if (typeof grecaptcha !== 'undefined') {
413    var captchaUrl = 'https://www.google.com/recaptcha/enterprise.js?render=',
414      $captchaScript = $("script[src*='" + captchaUrl + "']");
415    if ($captchaScript.length > 0) {
416      var captchaKey = $captchaScript.attr("src").substr(captchaUrl.length);
417      if (captchaKey) {
418        try {
419          grecaptcha.enterprise.execute(captchaKey, {
420            action: 'submit'
421          }).then(function(token) {
422            if ($form.find("input[name='g-recaptcha-response']").length === 0) {
423              $form.append("<input type='hidden' name='g-recaptcha-response' value='" + token + "'>");
424            } else {
425              $form.find("input[name='g-recaptcha-response']").val(token);
426            }
427            if(isCmsForm) {
428              $form.submit();;
429            } else {
430              submitFormUsingAjax(form_url, new FormData(document.getElementById(formID)));
431            }
432          });
433          return;
434        } catch (error) {
435          console.error(error);
436          if(isCmsForm) {
437            $form.submit();;
438          } else {
439            submitFormUsingAjax(form_url, new FormData(document.getElementById(formID)));
440          }
441        }
442      }
443    }
444  } else{
445    if(isCmsForm) {
446      $form.submit();;
447    } else {
448      submitFormUsingAjax(form_url, new FormData(document.getElementById(formID)));
449    }
450  }
451}
452
453function submitFormUsingAjax(form_url, formData) {
454  $.ajax({
455    url: form_url,
456    type: 'post',
457    data: formData,
458    contentType: false,
459    processData: false,
460     cache: false,  
461  }).done(function (result, status) {
462    if(result.succeeded === true){
463        if (result.redirectUri) {
464          setTimeout(function () {
465            window.location.replace(result.redirectUri);
466          }, 1000);
467        }
468    }
469  });
470};
471
472$(document).ready(function() {
473  inputChangeApteveForms();
474
475  if ($('.legalterms').length > 0) {
476    $('form .legalterms').each(function() {
477      var formLegalTermsCount = $('a', $(this)).length;
478      var legaltermsloopCount = 0;
479      $('a', $(this)).each(function() {
480        legaltermsloopCount++;
481        if (formLegalTermsCount === 2 && legaltermsloopCount < 2 || formLegalTermsCount === 3 && legaltermsloopCount === 2) {
482          $(this).after(' & ')
483        } else if (formLegalTermsCount === 3 && legaltermsloopCount === 1) {
484          $(this).after(', ')
485        }
486      })
487    })
488  }
489})
490// CACHED HIT END (RAM)

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.