PageSourceSearch

https://www.piratedirectory.co.uk/javascripts/forms-validation.js

js piratedirectory.co.uk collected 2026-10-06 02:52:25 UTC 1,571 bytes, 60 lines download raw bytes

1/*
2	New validation for forms - Last Updated by Bruleo : 2025-11-23
3*/
4document.addEventListener('DOMContentLoaded', () => {
5  const form = document.getElementById('submit_form');
6  if (!form) return;
7  
8	function checkFormValidity() {
9	  const submitBtn = document.getElementById('continue');
10	  if (!submitBtn) return;
11
12	  const errors = document.querySelectorAll('span[id$="_error"]');
13	  let hasErrors = false;
14	  errors.forEach(span => {
15		if (span.textContent.trim() !== '') {
16		  hasErrors = true;
17		}
18	  });
19
20	  submitBtn.disabled = hasErrors;
21	}
22
23  const fields = form.querySelectorAll('input[name], textarea[name]');
24  fields.forEach(field => {
25    field.addEventListener('blur', () => {
26      const errorSpan = document.getElementById(field.name + "_error");
27
28      fetch(window.location.pathname, {
29        method: 'POST',
30        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
31        body: `ajax_validate=1&field=${encodeURIComponent(field.name)}&value=${encodeURIComponent(field.value)}`
32      })
33      .then(res => res.json())
34		.then(data => {
35		  if (errorSpan) {
36			if (data.valid) {
37			  // clear any previous error
38			  errorSpan.textContent = '';
39			} else {
40			  // show the error message
41			  errorSpan.textContent = data.message;
42			}
43		  }
44		  checkFormValidity(); 
45		})
46				
47      .catch(err => {
48        console.error("AJAX error:", err);
49        if (errorSpan) errorSpan.textContent = "Validation failed";
50      });
51    });
52  });
53   checkFormValidity();
54});
55
56
57
58
59
60

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.