Browse Source

sweet alert

master
kirubaasagar.R 2 years ago
parent
commit
54113ddb03
  1. BIN
      cdwastecollectordocuments/cdwaste_adhaar_copy/WhatsApp Image 2024-09-16 at 5.41.07 PM (1).jpeg
  2. BIN
      cdwastecollectordocuments/cdwaste_adhaar_copy/WhatsApp Image 2024-09-16 at 5.41.07 PM.jpeg
  3. BIN
      cdwastecollectordocuments/cdwaste_adhaar_copy/WhatsApp Image 2024-09-16 at 5.41.08 PM.jpeg
  4. BIN
      cdwastecollectordocuments/cdwaste_adhaar_copy/aa.jpg
  5. BIN
      cdwastecollectordocuments/cdwaste_adhaar_copy/booking.png
  6. BIN
      cdwastecollectordocuments/cdwaste_adhaar_copy/calendar.png
  7. BIN
      cdwastecollectordocuments/cdwaste_adhaar_copy/id-card.png
  8. BIN
      cdwastecollectordocuments/cdwaste_adhaar_copy/ima.jpg
  9. BIN
      cdwastecollectordocuments/cdwaste_adhaar_copy/lockers.png
  10. BIN
      cdwastecollectordocuments/cdwaste_adhaar_copy/man.png
  11. BIN
      cdwastecollectordocuments/cdwaste_adhaar_copy/schedule.png
  12. BIN
      cdwastecollectordocuments/cdwaste_adhaar_copy/shower.png
  13. BIN
      cdwastecollectordocuments/cdwaste_rcbook_copy/WhatsApp Image 2024-08-24 at 12.49.58 PM.jpeg
  14. BIN
      cdwastecollectordocuments/cdwaste_rcbook_copy/WhatsApp Image 2024-09-12 at 9.54.20 PM.jpeg
  15. BIN
      cdwastecollectordocuments/cdwaste_rcbook_copy/WhatsApp Image 2024-09-16 at 5.41.07 PM (1).jpeg
  16. BIN
      cdwastecollectordocuments/cdwaste_rcbook_copy/WhatsApp Image 2024-09-16 at 5.41.07 PM.jpeg
  17. BIN
      cdwastecollectordocuments/cdwaste_rcbook_copy/booking.png
  18. BIN
      cdwastecollectordocuments/cdwaste_rcbook_copy/calendar.png
  19. BIN
      cdwastecollectordocuments/cdwaste_rcbook_copy/ima.jpg
  20. BIN
      cdwastecollectordocuments/cdwaste_rcbook_copy/lockers.png
  21. BIN
      cdwastecollectordocuments/cdwaste_rcbook_copy/plus.png
  22. BIN
      cdwastecollectordocuments/cdwaste_rcbook_copy/portable-toilet.png
  23. BIN
      cdwastecollectordocuments/cdwaste_rcbook_copy/received-card.png
  24. BIN
      cdwastecollectordocuments/cdwaste_rcbook_copy/search.png
  25. BIN
      cdwastecollectordocuments/cdwaste_rcbook_copy/shower.png
  26. BIN
      cdwastecollectordocuments/cdwaste_rcbook_copy/wardrobe.png
  27. 24
      src/main/java/com/volunteersregistration/config/DataSourceConfig.java
  28. 75
      src/main/java/com/volunteersregistration/controller/ApiController.java
  29. 10
      src/main/java/com/volunteersregistration/controller/VolunteerController.java
  30. 3
      src/main/java/com/volunteersregistration/controller/VolunteerRegistrationController.java
  31. 90
      src/main/java/com/volunteersregistration/service/Registrationservice.java
  32. 6
      src/main/resources/application.properties
  33. 18
      src/main/resources/templates/index.html
  34. 327
      src/main/resources/templates/wastecollectors.html

BIN
cdwastecollectordocuments/cdwaste_adhaar_copy/WhatsApp Image 2024-09-16 at 5.41.07 PM (1).jpeg

After

Width: 1280  |  Height: 720  |  Size: 119 KiB

BIN
cdwastecollectordocuments/cdwaste_adhaar_copy/WhatsApp Image 2024-09-16 at 5.41.07 PM.jpeg

After

Width: 1280  |  Height: 720  |  Size: 179 KiB

BIN
cdwastecollectordocuments/cdwaste_adhaar_copy/WhatsApp Image 2024-09-16 at 5.41.08 PM.jpeg

After

Width: 1280  |  Height: 720  |  Size: 129 KiB

BIN
cdwastecollectordocuments/cdwaste_adhaar_copy/aa.jpg

After

Width: 200  |  Height: 180  |  Size: 22 KiB

BIN
cdwastecollectordocuments/cdwaste_adhaar_copy/booking.png

After

Width: 512  |  Height: 512  |  Size: 35 KiB

BIN
cdwastecollectordocuments/cdwaste_adhaar_copy/calendar.png

After

Width: 512  |  Height: 512  |  Size: 22 KiB

BIN
cdwastecollectordocuments/cdwaste_adhaar_copy/id-card.png

After

Width: 512  |  Height: 512  |  Size: 14 KiB

BIN
cdwastecollectordocuments/cdwaste_adhaar_copy/ima.jpg

After

Width: 320  |  Height: 180  |  Size: 15 KiB

BIN
cdwastecollectordocuments/cdwaste_adhaar_copy/lockers.png

After

Width: 512  |  Height: 512  |  Size: 12 KiB

BIN
cdwastecollectordocuments/cdwaste_adhaar_copy/man.png

After

Width: 512  |  Height: 512  |  Size: 33 KiB

BIN
cdwastecollectordocuments/cdwaste_adhaar_copy/schedule.png

After

Width: 512  |  Height: 512  |  Size: 28 KiB

BIN
cdwastecollectordocuments/cdwaste_adhaar_copy/shower.png

After

Width: 512  |  Height: 512  |  Size: 40 KiB

BIN
cdwastecollectordocuments/cdwaste_rcbook_copy/WhatsApp Image 2024-08-24 at 12.49.58 PM.jpeg

After

Width: 738  |  Height: 1600  |  Size: 141 KiB

BIN
cdwastecollectordocuments/cdwaste_rcbook_copy/WhatsApp Image 2024-09-12 at 9.54.20 PM.jpeg

After

Width: 1080  |  Height: 1187  |  Size: 150 KiB

BIN
cdwastecollectordocuments/cdwaste_rcbook_copy/WhatsApp Image 2024-09-16 at 5.41.07 PM (1).jpeg

After

Width: 1280  |  Height: 720  |  Size: 119 KiB

BIN
cdwastecollectordocuments/cdwaste_rcbook_copy/WhatsApp Image 2024-09-16 at 5.41.07 PM.jpeg

After

Width: 1280  |  Height: 720  |  Size: 179 KiB

BIN
cdwastecollectordocuments/cdwaste_rcbook_copy/booking.png

After

Width: 512  |  Height: 512  |  Size: 35 KiB

BIN
cdwastecollectordocuments/cdwaste_rcbook_copy/calendar.png

After

Width: 512  |  Height: 512  |  Size: 22 KiB

BIN
cdwastecollectordocuments/cdwaste_rcbook_copy/ima.jpg

After

Width: 320  |  Height: 180  |  Size: 15 KiB

BIN
cdwastecollectordocuments/cdwaste_rcbook_copy/lockers.png

After

Width: 512  |  Height: 512  |  Size: 12 KiB

BIN
cdwastecollectordocuments/cdwaste_rcbook_copy/plus.png

After

Width: 512  |  Height: 512  |  Size: 25 KiB

BIN
cdwastecollectordocuments/cdwaste_rcbook_copy/portable-toilet.png

After

Width: 512  |  Height: 512  |  Size: 18 KiB

BIN
cdwastecollectordocuments/cdwaste_rcbook_copy/received-card.png

After

Width: 512  |  Height: 512  |  Size: 13 KiB

BIN
cdwastecollectordocuments/cdwaste_rcbook_copy/search.png

After

Width: 512  |  Height: 512  |  Size: 30 KiB

BIN
cdwastecollectordocuments/cdwaste_rcbook_copy/shower.png

After

Width: 512  |  Height: 512  |  Size: 40 KiB

BIN
cdwastecollectordocuments/cdwaste_rcbook_copy/wardrobe.png

After

Width: 512  |  Height: 512  |  Size: 20 KiB

24
src/main/java/com/volunteersregistration/config/DataSourceConfig.java

@ -0,0 +1,24 @@
package com.volunteersregistration.config;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableTransactionManagement
public class DataSourceConfig {
//////////////////////////////(For C & D Waste Collectors Registration ) ////////////////////////
@Bean(name = "volunteers")
public DataSource mysql1913CDwasteDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/volunteer");
dataSource.setUsername("root");
dataSource.setPassword("root");
return dataSource;
}
}

75
src/main/java/com/volunteersregistration/controller/ApiController.java

@ -0,0 +1,75 @@
package com.volunteersregistration.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.volunteersregistration.service.Registrationservice;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/gcc/api/registration")
public class ApiController {
@Autowired
private Environment environment;
private final Registrationservice registrationService;
public ApiController(Registrationservice registrationService) {
this.registrationService = registrationService;
}
@PostMapping("/register")
public ResponseEntity<List<Map<String, Object>>> registerCollector(
@RequestParam("name") String name,
@RequestParam("mobileNo") String mobileNo,
@RequestParam("address") String address,
@RequestParam("adhaar") MultipartFile adhaarFile,
@RequestParam("vehicleRcBook") MultipartFile vehicleRcBookFile) {
try {
// Save files to specified folders
String adhaarFolder = environment.getProperty("cdwaste_adhaar_foldername");
String vehicleRcFolder = environment.getProperty("cdwaste_rc_foldername");
// Create directories if they do not exist
Files.createDirectories(Paths.get(adhaarFolder));
Files.createDirectories(Paths.get(vehicleRcFolder));
// Define file paths
Path adhaarPath = Paths.get(adhaarFolder, adhaarFile.getOriginalFilename());
Path vehicleRcPath = Paths.get(vehicleRcFolder, vehicleRcBookFile.getOriginalFilename());
// Save files
adhaarFile.transferTo(adhaarPath);
vehicleRcBookFile.transferTo(vehicleRcPath);
// Now call the service to save the registration data
List<Map<String, Object>> result = registrationService.saveRegistration(name, mobileNo, address, adhaarFile, vehicleRcBookFile);
if (result.isEmpty()) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(Collections.singletonList(Map.of("status", "error", "message", "Error registering collector!")));
}
return ResponseEntity.ok(result);
} catch (IOException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(Collections.singletonList(Map.of("status", "error", "message", "Error uploading files: " + e.getMessage())));
}
}
}

10
src/main/java/com/volunteersregistration/controller/VolunteerController.java

@ -16,4 +16,14 @@ public class VolunteerController {
model.addAttribute("ref",ref); model.addAttribute("ref",ref);
return "index"; return "index";
} }
@GetMapping(value={"/wastecollectors"})
public String wastecollectors(Model model){
return "wastecollectors";
}
} }

3
src/main/java/com/volunteersregistration/controller/VolunteerRegistrationController.java

@ -34,4 +34,7 @@ public class VolunteerRegistrationController {
System.out.println("save volunteers....."); System.out.println("save volunteers.....");
return volunteerRegistrationService.registerAsNgo(ngoInfo); return volunteerRegistrationService.registerAsNgo(ngoInfo);
} }
} }

90
src/main/java/com/volunteersregistration/service/Registrationservice.java

@ -0,0 +1,90 @@
package com.volunteersregistration.service;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@Service
public class Registrationservice {
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private Environment environment;
@Autowired
public void setDataSource(@Qualifier("volunteers") DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
public List<Map<String, Object>> saveRegistration(String name, String mobileNo, String address, MultipartFile adhaarFile, MultipartFile vehicleRcBookFile) throws IOException {
// Define directory paths from application.properties
String adhaarDir = environment.getProperty("cdwaste_adhaar_foldername");
String rcBookDir = environment.getProperty("cdwaste_rc_foldername");
// Ensure directories exist
File adhaarFolder = new File(adhaarDir);
File rcBookFolder = new File(rcBookDir);
if (!adhaarFolder.exists()) {
adhaarFolder.mkdirs();
}
if (!rcBookFolder.exists()) {
rcBookFolder.mkdirs();
}
// Generate unique file names to avoid overwriting existing files
String adhaarFileName = adhaarFile.getOriginalFilename();
String rcBookFileName = vehicleRcBookFile.getOriginalFilename();
// Paths where files will be stored
String adhaarFilePath = adhaarFolder.getAbsolutePath() + File.separator + adhaarFileName;
String rcBookFilePath = rcBookFolder.getAbsolutePath() + File.separator + rcBookFileName;
// Save the files to the specified directories
adhaarFile.transferTo(new File(adhaarFilePath));
vehicleRcBookFile.transferTo(new File(rcBookFilePath));
// File URLs to be saved in the database (adjust as per your URL structure)
String adhaarUrl = "/uploads/" + adhaarFileName;
String rcBookUrl = "/uploads/" + rcBookFileName;
// SQL INSERT query (saving URLs)
String sqlQuery = "INSERT INTO registration (name, mobile_no, address, adhaar, vehicle_rc_book) VALUES (?, ?, ?, ?, ?)";
int rowsAffected = jdbcTemplate.update(sqlQuery, name, mobileNo, address, adhaarUrl, rcBookUrl);
// Prepare the response
List<Map<String, Object>> response = new ArrayList<>();
Map<String, Object> result = new HashMap<>();
if (rowsAffected > 0) {
result.put("status", "success");
result.put("message", "Collector registered successfully!");
} else {
result.put("status", "error");
result.put("message", "No rows affected. Registration failed!");
}
response.add(result);
return response;
}
}

6
src/main/resources/application.properties

@ -2,8 +2,12 @@ spring.application.name=volunteersregistration
spring.datasource.url=jdbc:mysql://localhost:3306/volunteer spring.datasource.url=jdbc:mysql://localhost:3306/volunteer
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=gccroot
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true spring.jpa.show-sql=true
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
server.port=8071 server.port=8071
#//////// For C&D Waste Collector Project//////////////////
cdwaste_adhaar_foldername=cdwastecollectordocuments/cdwaste_adhaar_copy
cdwaste_rc_foldername=cdwastecollectordocuments/cdwaste_rcbook_copy

18
src/main/resources/templates/index.html

@ -159,6 +159,7 @@
</div> </div>
<div class="container mt-5"> <div class="container mt-5">
<form onsubmit="return validateForm();"> <form onsubmit="return validateForm();">
<!-- Dropdowns for selecting category and subcategory --> <!-- Dropdowns for selecting category and subcategory -->
@ -905,7 +906,7 @@
$("#nameError").text("Please Enter Name !"); $("#nameError").text("Please Enter Name !");
isValid = false; isValid = false;
} }
if (dob == undefined || dob == "") { if (dob == undefined || dob == "") {
$("#dobError").text("Please enter a Date of birth"); $("#dobError").text("Please enter a Date of birth");
isValid = false; isValid = false;
@ -1121,11 +1122,13 @@
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(volunteerData), data: JSON.stringify(volunteerData),
success: function (response) { success: function (response) {
successPopup(response); successPopup(response);
}, },
error: function (error) { error: function (error) {
alert("Error saving data!"); alert("Error saving data!");
console.log(error); console.log(error);
} }
}); });
return false; return false;
@ -1155,17 +1158,20 @@
referBy: $("#ref").val(), referBy: $("#ref").val(),
preferredAreas: preferredAreas preferredAreas: preferredAreas
} }
$('#loader').show();
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "/volunteer/api/registerAsCorporate", url: "/volunteer/api/registerAsCorporate",
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(copInfo), data: JSON.stringify(copInfo),
success: function (response) { success: function (response) {
$('#loader').hide();
successPopup(response); successPopup(response);
}, },
error: function (error) { error: function (error) {
alert("Error saving data!"); alert("Error saving data!");
console.log(error); console.log(error);
$('#loader').hide();
} }
}); });
return false; return false;
@ -1197,7 +1203,7 @@
referBy: $("#ref").val(), referBy: $("#ref").val(),
preferredAreas: preferredAreas preferredAreas: preferredAreas
} }
$('#loader').show();
$.ajax({ $.ajax({
type: "POST", type: "POST",
@ -1205,11 +1211,13 @@
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(ngoInfo), data: JSON.stringify(ngoInfo),
success: function (response) { success: function (response) {
$('#loader').hide();
successPopup(response); successPopup(response);
}, },
error: function (error) { error: function (error) {
alert("Error saving data!"); alert("Error saving data!");
console.log(error); console.log(error);
$('#loader').hide();
} }
}); });
return false; return false;
@ -1221,7 +1229,10 @@
Swal.fire({ Swal.fire({
title: "Good job!", 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", 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"
icon: "success",
allowOutsideClick: false,
allowEscapeKey: false,
allowEnterKey: false
}).then((result) => { }).then((result) => {
if (result.isConfirmed) { if (result.isConfirmed) {
window.location.href = "https://chennaicorporation.gov.in/gcc/"; // Redirect to the desired URL window.location.href = "https://chennaicorporation.gov.in/gcc/"; // Redirect to the desired URL
@ -1230,6 +1241,7 @@
} }
</script> </script>
</body> </body>

327
src/main/resources/templates/wastecollectors.html

@ -0,0 +1,327 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>GCC - Volunteers</title>
<!-- Bootstrap CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<!-- SweetAlert CSS -->
<!--
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css">
-->
<!-- Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<!-- SweetAlert JS -->
<!--
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<style>
/*for radio button style*/
.radio-group {
display: flex;
align-items: center;
/* Ensures all items are aligned to the center */
}
.radio-item {
display: flex;
align-items: center;
margin-right: 20px;
/* Adds space between each radio item */
}
.radio-item input[type="radio"] {
margin-right: 10px;
/* Adds space between the radio button and its label */
vertical-align: middle;
/* Ensures vertical alignment */
}
.radio-item label {
margin: 0;
/* Removes any default margins that might affect alignment */
}
/*for radio button style*/
/*checkbox style*/
.zone-checkbox-label {
display: inline-block;
padding: 10px 15px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f8f9fa;
font-size: 16px;
cursor: pointer;
text-align: center;
width: 100%;
}
.zone-checkbox {
margin-right: 10px;
}
.form-check {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.form-check-input {
transform: scale(1.5);
}
/*checkbox style*/
label {
color: #858585;
}
/* Header Styling */
.header {
background-color: #1d495a;
padding: 10px 20px;
display: flex;
align-items: center;
justify-content: space-between;
color: white;
font-family: Arial, sans-serif;
}
.header .logo {
display: flex;
align-items: center;
}
.header .logo img {
height: 60px;
}
.header .menu {
display: flex;
justify-content: center;
align-items: center;
flex-grow: 1;
margin-left: 20px;
}
.header .menu a {
color: white;
margin: 0 15px;
text-decoration: none;
}
.header .menu a:hover {
text-decoration: underline;
}
.required{
color:red;
}
</style>
</head>
<body style="background-color: #ebf1fa;">
<h1 style="display: none;">GCC Volunteers</h1>
<h1 style="display: none;">GCC Volunteers Registration</h1>
<h1 style="display: none;">Chennai Volunteers </h1>
<h1 style="display: none;">Volunteers </h1>
<!-- Header Section -->
<div class="header">
<!-- Left Logo -->
<div class="logo">
<img src="https://gccservices.in/gcc/assets/images/logo.png" alt="Greater Chennai Corporation Logo">
<span class="ml-2">GREATER CHENNAI CORPORATION</span>
</div>
<!-- Center Menu -->
<div class="menu">
<a href="https://chennaicorporation.gov.in/gcc/">Home</a>
<a href="https://chennaicorporation.gov.in/gcc/about-GCC/">About GCC</a>
<a href="https://chennaicorporation.gov.in/gcc/who-is-who/index_data.jsp">Who'sWho</a>
<a href="https://chennaicorporation.gov.in/gcc/council/about-council/">Council</a>
<a href="https://chennaicorporation.gov.in/gcc/tender/">Tender</a>
<a href="https://chennaicorporation.gov.in/gcc/department/">Departments</a>
<a href="https://chennaicorporation.gov.in/gcc/online-services/">Online Services</a>
</div>
</div>
<div class="container mt-5">
<form onsubmit="return validateForm();">
<!-- Dropdowns for selecting category and subcategory -->
<!-- Bootstrap Card for displaying uploaded details -->
<div class="card" style="background-color: white;">
<div class="card-header text-center" style="color: #1d4859;">
<h3>C&D Waste Collectors Registration Form</h3>
</div>
<div class="card-body">
<!--form-->
<div class="row">
<div class="col-md-12">
<div class="card" style="margin-top: 0px;">
<!--<div class="card-header justify-content-between align-items-center">
<h3><b>Registration Form</b></h3>
</div>-->
<div class="card-body">
<form id="cdwasteRegistrationForm">
<div class="form-group">
<div class="row">
<div class="col-sm-12 col-md-6">
<label for="name">Name<span class="required">*</span></label>
<input type="text" class="form-control" id="name"
placeholder="Enter Name" required>
</div>
<div class="col-sm-12 col-md-6">
<label for="mobileNo">Mobile No<span
class="required">*</span></label>
<input type="number" class="form-control" id="mobileNo"
placeholder="Mobile No" required>
</div>
</div>
</div>
<div class="form-group">
<label for="address">Address<span class="required">*</span></label>
<textarea class="form-control" id="address" rows="2" required></textarea>
</div>
<div class="form-group">
<label for="adhaar">Upload Aadhaar:<span class="required">*</span></label>
<input type="file" class="form-control" id="adhaarFile" required>
</div>
<div class="form-group">
<label for="vehicleRcBook">Upload Vehicle RC Book:<span
class="required">*</span></label>
<input type="file" class="form-control" id="vehicleRcBookFile" required>
</div>
<div class="form-group text-center">
<button type="submit" class="btn btn-primary"
id="registerSubmit">Submit</button>
<button type="reset" class="btn btn-secondary ml-2"
onclick="resetForm()">Reset</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!--form-->
</div>
</div>
</form>
</div>
<script>
$(document).ready(function () {
$('#registerSubmit').on('click', function (event) {
event.preventDefault(); // Prevent form from submitting the traditional way
var name = $('#name').val();
var mobileNo = $('#mobileNo').val();
var address = $('#address').val();
var adhaarFile = $('#adhaarFile')[0].files[0];
var vehicleRcBookFile = $('#vehicleRcBookFile')[0].files[0];
if (!name || !mobileNo || !address || !adhaarFile || !vehicleRcBookFile) {
Swal.fire({
icon: 'error',
title: 'Error',
text: 'Please fill in all fields and upload a file before submitting.',
});
return; // Stop form submission if any field is empty
}
// Create a FormData object to hold the form data, including files
var formData = new FormData();
formData.append('name', name);
formData.append('mobileNo', mobileNo);
formData.append('address', address);
formData.append('adhaar', adhaarFile); // Add Aadhaar file
formData.append('vehicleRcBook', vehicleRcBookFile); // Add Vehicle RC Book file
// Make an AJAX request to submit the form data
$.ajax({
url: '/gcc/api/registration/register', // Your API endpoint for registration
type: 'POST',
data: formData,
processData: false, // Required for FormData
contentType: false, // Required for FormData
success: function (response) {
if (response[0].status === 'success') {
Swal.fire({
icon: 'success',
title: 'Success',
text: response[0].message
}).then((result) => {
if (result.isConfirmed) {
// Optionally reset the form
window.location.reload(true);
}
});
} else {
Swal.fire({
icon: 'error',
title: 'Error',
text: response[0].message
});
}
},
error: function (xhr, status, error) {
Swal.fire({
icon: 'error',
title: 'Error',
text: 'An error occurred: ' + error
});
}
});
});
});
</script>
</body>
</html>
Loading…
Cancel
Save