form validation for new fields
This commit is contained in:
		
							parent
							
								
									9543ba00f8
								
							
						
					
					
						commit
						7cc94ad1aa
					
				@ -4,6 +4,10 @@ function registerFormValidators(formId) {
 | 
			
		||||
	var email = form.querySelector('input[name="email"]');
 | 
			
		||||
	var phone = form.querySelector('input[name="phone"]');
 | 
			
		||||
	var subject = form.querySelector('input[name="subject"]');
 | 
			
		||||
    var position = form.querySelector('input[name="position"]');
 | 
			
		||||
    var address = form.querySelector('input[name="address"]');
 | 
			
		||||
    var quantity = form.querySelector('input[name="quantity"]');
 | 
			
		||||
    var wireStake = form.querySelector('input[name="wire_stake"]');
 | 
			
		||||
	var message = form.querySelector('textarea[name="message"]');
 | 
			
		||||
	var submit = form.querySelector('button[type="submit"]');
 | 
			
		||||
 | 
			
		||||
@ -52,6 +56,36 @@ function registerFormValidators(formId) {
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (address) {
 | 
			
		||||
		address.addEventListener('input', function (e) {
 | 
			
		||||
			if (!address.value) {
 | 
			
		||||
				address.classList.add('invalid');
 | 
			
		||||
			} else {
 | 
			
		||||
				address.classList.remove('invalid');
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (position) {
 | 
			
		||||
		position.addEventListener('input', function (e) {
 | 
			
		||||
			if (!position.value) {
 | 
			
		||||
				position.classList.add('invalid');
 | 
			
		||||
			} else {
 | 
			
		||||
				position.classList.remove('invalid');
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (quantity) {
 | 
			
		||||
		quantity.addEventListener('input', function (e) {
 | 
			
		||||
			if (!quantity.value) {
 | 
			
		||||
				quantity.classList.add('invalid');
 | 
			
		||||
			} else {
 | 
			
		||||
				quantity.classList.remove('invalid');
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (submit) {
 | 
			
		||||
		submit.addEventListener('click', function (e) {
 | 
			
		||||
			e.preventDefault();
 | 
			
		||||
@ -72,6 +106,14 @@ function registerFormValidators(formId) {
 | 
			
		||||
				alert("Your message is invalid.");
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			if (address && !address.value) {
 | 
			
		||||
				alert("Your address is invalid.");
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			if (position && !position.value) {
 | 
			
		||||
				alert("Your volunteer position is invalid.");
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			var fd = new FormData();
 | 
			
		||||
			if (fullName)
 | 
			
		||||
				fd.append('full_name', fullName.value);
 | 
			
		||||
@ -83,6 +125,14 @@ function registerFormValidators(formId) {
 | 
			
		||||
				fd.append('message', message.value);
 | 
			
		||||
			if (subject)
 | 
			
		||||
				fd.append('subject', subject.value);
 | 
			
		||||
            if (address)
 | 
			
		||||
                fd.append('address', address.value);
 | 
			
		||||
            if (position)
 | 
			
		||||
                fd.append('position', position.value);
 | 
			
		||||
            if (quantity)
 | 
			
		||||
                fd.append('quantity', quantity.value);
 | 
			
		||||
            if (wireStake)
 | 
			
		||||
                fd.append('wire_stake', wireStake.value);
 | 
			
		||||
			fetch(form.action, {
 | 
			
		||||
				method: 'POST',
 | 
			
		||||
				body: fd
 | 
			
		||||
@ -106,6 +156,8 @@ function registerFormValidators(formId) {
 | 
			
		||||
						message.value = "";
 | 
			
		||||
					if (subject)
 | 
			
		||||
						subject.value = "";
 | 
			
		||||
                    if (address)
 | 
			
		||||
                        address.value = "";
 | 
			
		||||
				}
 | 
			
		||||
			});
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user