From 05da021c168e8f8b5e28e5ce05965948b24b0ff9 Mon Sep 17 00:00:00 2001 From: "kirubaasagar.R" Date: Thu, 19 Sep 2024 22:06:57 +0530 Subject: [PATCH] validation added --- src/main/resources/application.properties | 4 +- src/main/resources/templates/index.html | 2273 +++++++++++---------- 2 files changed, 1177 insertions(+), 1100 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9d5e53e..07e6010 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,8 +1,8 @@ spring.application.name=volunteersregistration -spring.datasource.url=jdbc:mysql://localhost:3306/volunteers +spring.datasource.url=jdbc:mysql://localhost:3306/volunteer spring.datasource.username=root -spring.datasource.password=root +spring.datasource.password=gccroot spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 9c31872..3a7f981 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -2,90 +2,90 @@ - - Chennai-Corporation - - - - - + + + + - - - - - - + + + + + - - - - - + + .req { + color: red; + + } + - -
- - - - - -
-
- -
- - - - - -
- -
-

Volunteer Information

-
-
- - -
-
- - -
-
- - - -
- - -

Contact Details

-
-
- - -
- -
-
-
- - -
- - -
- - - -
-
-
-
- -
-
- - -
-
- - -
-
- - -
-
-
- - -
- -
-
- +91 -
- -
-
- -
-
-
- -
-
- 044 -
- -
-
-
- - -
- -
-
-
- - -
- - -
- - - -
-
- - -

Education Qualification Details

-
-
- - -
- - -
- - - -
-
- - -
-
- -
-
- - -
-
- - -
- -
-
- -
- -
-
- - -
-
- - -
- -
-
- -
- -

Employment Details

-
-
- - -
- - - -
- -

Other Information

-
-
- - -
-
- -
-
- - -
-
- - -
- -
-
- - -
-
- - - - -
- - -

Contact Details

-
-
- - -
- - -
- - -
- - - -
- -
- -
- - -
- -
-
-
- - -
- - -
- - - -
-
- - -

No of volunteers from your Company *

-
-
- -
-
-

Point of Contact

-
-
- - -
-
- - -
-
-
- -
- - - -
- -
- - - -
- -
- -
- -
- -
-
- - -
-
- - -
- -
-
- - -
-
- - - -
- - -

Contact Details

-
-
- - -
- - -
- - -
- - - -
- -
- -
- - -
- -
-
-
- - -
- - -
- - - -
-
- - -

No of volunteers from your Organization *

-
-
- -
-
-

Point of Contact

-
-
- - -
-
- - -
-
-
-
- - -
- - -
- - - -
-
- -
- -
- -
-
- - -
-
- - -
- -
-
- - -
-
- - - - - -
Preferred area of work *
-
- - -
-
- -
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
- - -
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
- - -
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
- - -
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- -
- -
-
-
-
-
- - - - - + } else if (category === "Corporate") { + document.querySelector('.corporate-form').style.display = 'block'; + subcategory.innerHTML += ``; + } else if (category === "NGO") { + document.querySelector('.ngo-form').style.display = 'block'; + subcategory.innerHTML += ``; + } + } + function uncheckAnyArea() { + + } + function checkAnyArea() { + var anyArea = document.getElementById("anyArea").checked; + if (anyArea) { + for (var i = 1; i <= 15; i++) { + document.getElementById("zone" + i).checked = false; + } + } + } + + let emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/; + let mobilePattern = /^[0-9]{10}$/; + let pincodePattern = /^[0-9]{6}$/; + function validateForm() { + + var isValid = true; + $('.text-danger').text(''); + var i = 0; + $(".zone-checkbox:checked").each(function () { + if ($(this).val()) { + i++; + }; + }); + var category = document.getElementById("category").value; + if (category == undefined || category === "-1") { + $("#categoryError").text("Please Select Category"); + isValid = false; + } + if (category === "Individual") { + var subcategory = document.getElementById("subcategory").value; + var name = document.getElementById("name").value = document.getElementById("name").value.trim(); + var email = document.getElementById("email").value = document.getElementById("email").value.trim(); + let genderSelected = document.querySelector('input[name="gender"]:checked'); + var mobile = document.getElementById("mobile").value = document.getElementById("mobile").value.trim(); + var address = document.getElementById("address").value = document.getElementById("address").value.trim(); + var pincode = document.getElementById("pincode").value = document.getElementById("pincode").value.trim(); + var edu = document.getElementById("edu").value = document.getElementById("edu").value.trim(); + var college = document.getElementById("college").value = document.getElementById("college").value.trim(); + let nssSelected = document.querySelector('input[name="nss"]:checked'); + let nccSelected = document.querySelector('input[name="ncc"]:checked'); + // var occupation = document.getElementById("occupation").value= document.getElementById("occupation").value.trim(); + // var designation = document.getElementById("designation").value= document.getElementById("designation").value.trim(); + let preVolSelected = document.querySelector('input[name="preVol"]:checked'); + var ngoAny = document.getElementById("ngoAny").value = document.getElementById("ngoAny").value.trim(); + var dob = document.getElementById("dob").value = document.getElementById("dob").value.trim(); + if (subcategory == -1) { + $("#subcategoryError").text("Please Select SubCategory !"); + isValid = false; + } + if (name == undefined || name == "") { + $("#nameError").text("Please Enter Name !"); + isValid = false; + } + + if (dob == undefined || dob == "") { + $("#dobError").text("Please enter a Date of birth"); + isValid = false; + } + if (!genderSelected) { + $("#genderError").text("Please Select Gender !"); + isValid = false; + } + if (mobile === "" || !mobilePattern.test(mobile)) { + $("#mobileError").text("Please enter a valid 10-digit mobile number"); + isValid = false; + } + if (address == undefined || address == "") { + $("#addressError").text("Please Enter address !"); + isValid = false; + } + // Pincode validation + if (pincode === "" || !pincodePattern.test(pincode)) { + $("#pincodeError").text("Please enter a valid 6-digit pincode"); + isValid = false; + } + if (edu == undefined || edu == "") { + $("#eduError").text("Please Enter Education details !"); + isValid = false; + } + if (college == undefined || college == "") { + $("#collegeError").text("Please Enter college details !"); + isValid = false; + } + if (!nssSelected) { + $("#nssError").text("Please Select NSS details !"); + isValid = false; + } + if (!nccSelected) { + $("#nccError").text("Please Select NCC details !"); + isValid = false; + } + /* if( occupation == undefined ||occupation == ""){ + alert("Please Enter Occupation details !"); + return false; + } + if(designation == undefined || designation == ""){ + alert("Please Enter Designation details !"); + return false; + } */ + if (!preVolSelected) { + $("#prevolError").text("Please Select Previous Volunteer details !"); + isValid = false; + } + if (ngoAny == undefined || ngoAny == "") { + $("#ngoAnyError").text("Please Enter Company/NGO details !"); + isValid = false; + } + if (i == 0) { + $("#anyAreaError").text("Please select Preferred Area details !"); + isValid = false; + } + if (isValid) { + saveTheIndividualForm(); + } + return false; + } + else if (category === "Corporate") { + var cmpName = document.getElementById("cmpName").value = document.getElementById("cmpName").value.trim(); + var cmpEmail = document.getElementById("cmpEmail").value = document.getElementById("cmpEmail").value.trim(); + var cmpLandline = document.getElementById("cmpLandline").value = document.getElementById("cmpLandline").value.trim(); + var cmpMobile = document.getElementById("cmpMobile").value = document.getElementById("cmpMobile").value.trim(); + var cmpAddress = document.getElementById("cmpAddress").value = document.getElementById("cmpAddress").value.trim(); + var cmpPincode = document.getElementById("cmpPincode").value = document.getElementById("cmpPincode").value.trim(); + var cmpNov = document.getElementById("cmpNov").value = document.getElementById("cmpNov").value.trim(); + var cmpPoc = document.getElementById("cmpPoc").value = document.getElementById("cmpPoc").value.trim(); + var cmdPom = document.getElementById("cmdPom").value = document.getElementById("cmdPom").value.trim(); + var cmpPVolSelect = document.querySelector('input[name="cmpPVol"]:checked'); + var cmdPoE = document.getElementById("cmdPoE").value = document.getElementById("cmdPoE").value.trim(); + + if (cmpName == undefined || cmpName == "") { + $("#cmpNameError").text("Please Enter Company Name"); + isValid = false; + } + if (cmpAddress == undefined || cmpAddress == "") { + $("#cmpAddressError").text("Please Enter Company Address"); + isValid = false; + } + if (cmpPincode == undefined || cmpPincode == "") { + $("#cmpPincodeError").text("Please Enter Pincode "); + isValid = false; + } + if (cmpNov == undefined || cmpNov == "") { + $("#cmpNovError").text("Please Enter No of Volunteer"); + isValid = false; + } + if (cmpPoc == undefined || cmpPoc == "") { + $("#cmpPocError").text("Please Enter Point of Conduct Name"); + isValid = false; + } + if (cmdPoE === "" || !emailPattern.test(cmdPoE)) { + $("#cmdPoEError").text("Please enter Point of Conduct a valid Email ID"); + isValid = false; + } + if (cmdPom == undefined || cmdPom == "" || !mobilePattern.test(cmdPom)) { + $("#cmdPomError").text("Please enter Point of Conduct Valid Mobile No"); + isValid = false; + } + if (!cmpPVolSelect) { + $("#anyAreaError").text("Please Select previous volunteers details"); + isValid = false; + } + if (i == 0) { + alert("Please select Preferred Area details !"); + isValid = false; + } + if (isValid) { + saveCorporateDetails(); + } + return false; + } + + else if (category === "NGO") { + var cmpName = document.getElementById("ngoOrgName").value = document.getElementById("ngoOrgName").value.trim(); + var ngoOrgEmail = document.getElementById("ngoOrgEmail").value = document.getElementById("ngoOrgEmail").value.trim(); + var cmpLandline = document.getElementById("oLandline").value = document.getElementById("oLandline").value.trim(); + var cmpMobile = document.getElementById("oMobile").value = document.getElementById("oMobile").value.trim(); + var cmpAddress = document.getElementById("oAddress").value = document.getElementById("oAddress").value.trim(); + var cmpPincode = document.getElementById("oPincode").value = document.getElementById("oPincode").value.trim(); + var cmpNov = document.getElementById("oNvol").value = document.getElementById("oNvol").value.trim(); + var cmpPoc = document.getElementById("oPoc").value = document.getElementById("oPoc").value.trim(); + var cmdPom = document.getElementById("oPom").value = document.getElementById("oPom").value.trim(); + var cmpPVolSelect = document.querySelector('input[name="oPvolY"]:checked'); + var oPoE = document.getElementById("oPoE").value = document.getElementById("oPoE").value.trim(); + + if (cmpName == undefined || cmpName == "") { + $("#ngoOrgNameError").text("Please Enter Organisation Name"); + isValid = false; + } + if (cmpAddress == undefined || cmpAddress == "") { + $("#oAddressError").text("Please Enter Organisation Address"); + isValid = false; + } + if (cmpPincode == undefined || cmpPincode == "") { + $("#oPincodeError").text("Please Enter Pincode "); + isValid = false; + } + if (cmpNov == undefined || cmpNov == "") { + $("#oNvolError").text("Please Enter No of Volunteer"); + isValid = false; + } + if (cmpPoc == undefined || cmpPoc == "") { + $("#oPocError").text("Please Enter Point of Conduct Name"); + isValid = false; + } + if (oPoE === "" || !emailPattern.test(oPoE)) { + $("#oPoeError").text("Please enter Point of Conduct valid Email ID"); + isValid = false; + } + if (cmdPom == undefined || cmdPom == "" || !mobilePattern.test(cmdPom)) { + $("#oPomError").text("Please Enter Point of Conduct Mobile No"); + isValid = false; + } + if (!cmpPVolSelect) { + $("#oPvolYError").text("Please Select previous volunteers details"); + isValid = false; + } + if (i == 0) { + alert("Please select Preferred Area details !"); + isValid = false; + } + if (isValid) { + saveNGODetails(); + } + return false; + + } + + return false; + } + + function saveTheIndividualForm() { + var preferredAreas = []; + $(".zone-checkbox:checked").each(function () { + preferredAreas.push($(this).val()); + }); + + // Create JSON object with form data + var volunteerData = { + category: $("#category").val(), + subCategory: $("#subcategory").val(), + name: $("#name").val(), + email: $("#email").val(), + dob: $("#dob").val(), + gender: $("input[name='gender']:checked").val(), + mobile_no: $("#mobile").val(), + landline_no: $("#landline").val(), + district: $("#district").val(), + address: $("#address").val(), + pin_code: $("#pincode").val(), + degree: $("#edu").val(), + college_name: $("#college").val(), + vol_nss: $("input[name='nss']:checked").val(), + vol_ncc: $("input[name='ncc']:checked").val(), + occupation: $("#occupation").val(), + designation: $("#designation").val(), + ngo_associated: $("#ngoAny").val(), + previous_volunteered: $("input[name='preVol']:checked").val(), + // Add more fields if needed + referBy: $("#ref").val(), + preferredAreas: preferredAreas + }; + + // Send AJAX POST request + $.ajax({ + type: "POST", + url: "/volunteer/api/register", + contentType: "application/json", + data: JSON.stringify(volunteerData), + success: function (response) { + successPopup(response); + }, + error: function (error) { + alert("Error saving data!"); + console.log(error); + } + }); + return false; + } + + function saveCorporateDetails() { + var preferredAreas = []; + $(".zone-checkbox:checked").each(function () { + preferredAreas.push($(this).val()); + }); + var copInfo = { + category: $("#category").val(), + subCategory: $("#subcategory").val(), + compName: $("#cmpName").val(), + compEmail: $("#cmpEmail").val(), + landline: $("#cmpLandline").val(), + mobileNo: $("#cmpMobile").val(), + district: $("#cmpDistrict").val(), + address: $("#cmpAddress").val(), + pinCode: $("#cmpPincode").val(), + no_of_vol: $("#cmpNov").val(), + contactPerson: $("#cmpPoc").val(), + contactPerMobile: $("#cmdPom").val(), + cntPerEmail: $("#cmdPoE").val(), + cntPerDesign: $("#cmdPod").val(), + previous_volunteered: $("input[name='cmpPVol']:checked").val(), + referBy: $("#ref").val(), + preferredAreas: preferredAreas + } + $.ajax({ + type: "POST", + url: "/volunteer/api/registerAsCorporate", + contentType: "application/json", + data: JSON.stringify(copInfo), + success: function (response) { + successPopup(response); + }, + error: function (error) { + alert("Error saving data!"); + console.log(error); + } + }); + return false; + + } + + + function saveNGODetails() { + var preferredAreas = []; + $(".zone-checkbox:checked").each(function () { + preferredAreas.push($(this).val()); + }); + var ngoInfo = { + category: $("#category").val(), + subCategory: $("#subcategory").val(), + orgName: $("#ngoOrgName").val(), + orgEmail: $("#ngoOrgEmail").val(), + landline: $("#oLandline").val(), + mobileNo: $("#oMobile").val(), + district: $("#oDistrict").val(), + address: $("#oAddress").val(), + pinCode: $("#oPincode").val(), + no_of_vol: $("#oNvol").val(), + contactPerson: $("#oPoc").val(), + contactPerMobile: $("#oPom").val(), + cntPerEmail: $("#oPoE").val(), + cntPerDesign: $("#oPod").val(), + previous_volunteered: $("input[name='oPvolY']:checked").val(), + referBy: $("#ref").val(), + preferredAreas: preferredAreas + } + + + $.ajax({ + type: "POST", + url: "/volunteer/api/registerAsNgo", + contentType: "application/json", + data: JSON.stringify(ngoInfo), + success: function (response) { + successPopup(response); + }, + error: function (error) { + alert("Error saving data!"); + console.log(error); + } + }); + return false; + + + } + + function successPopup(id) { + Swal.fire({ + title: "Good job!", + text: "Thank you for registering as a volunteer \nwith the Greater Chennai Corporation for monsoon support! \nYour registration is successful, and your reference number is [GCC-" + id + "]. \nYou will be contacted once the final listing is complete and deployment details \nare confirmed. Together, we can help Chennai stay safe this monsoon", + icon: "success" + }).then((result) => { + if (result.isConfirmed) { + window.location.href = "https://chennaicorporation.gov.in/gcc/"; // Redirect to the desired URL + } + }); + } + + + \ No newline at end of file