Skip to content
Snippets Groups Projects
Commit fc165012 authored by Rhys Evans's avatar Rhys Evans
Browse files

Further work on front end and back end verification

parent cb186521
No related branches found
No related tags found
1 merge request!13Resolve "As a user I want to be able submit a form about a specific landmark to add to the trail"
package Team5.SmartTowns.Landmarks; package Team5.SmartTowns.Landmarks;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@Data @Data
@AllArgsConstructor
public class Landmarks { public class Landmarks {
@NotEmpty(message = "You must type in a username.")
private String landmarkName; private String landmarkName;
@Email(message = "You must attach a contact address.")
private String landmarkEmail; private String landmarkEmail;
private String landmarkDescription; private String landmarkDescription;
private String landmarkLocation; private String landmarkLocation;
...@@ -20,11 +25,11 @@ public class Landmarks { ...@@ -20,11 +25,11 @@ public class Landmarks {
this.trailID =0; this.trailID =0;
} }
public Landmarks(String landmarkName, String landmarkEmail, String landmarkDescription, String landmarkLocation, Integer trailID) { // public Landmarks(String landmarkName, String landmarkEmail, String landmarkDescription, String landmarkLocation, Integer trailID) {
this.landmarkName = landmarkName; // this.landmarkName = landmarkName;
this.landmarkEmail = landmarkEmail; // this.landmarkEmail = landmarkEmail;
this.landmarkDescription = landmarkDescription; // this.landmarkDescription = landmarkDescription;
this.landmarkLocation = landmarkLocation; // this.landmarkLocation = landmarkLocation;
this.trailID = trailID; // this.trailID = trailID;
} // }
} }
package Team5.SmartTowns.Landmarks; package Team5.SmartTowns.Landmarks;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
...@@ -15,7 +16,7 @@ public class LandmarksController { ...@@ -15,7 +16,7 @@ public class LandmarksController {
@GetMapping("/landmarkSubmission") @GetMapping("/landmarkSubmission")
public ModelAndView landmarkSubmission(){ public ModelAndView landmarkSubmission(){
ModelAndView modelAndView1 = new ModelAndView("LandmarkFormTh.html"); ModelAndView modelAndView1 = new ModelAndView("Landmarks/LandmarkFormTh.html");
modelAndView1.addObject("landmarkData", new Landmarks()); modelAndView1.addObject("landmarkData", new Landmarks());
return modelAndView1; return modelAndView1;
...@@ -23,9 +24,15 @@ public class LandmarksController { ...@@ -23,9 +24,15 @@ public class LandmarksController {
@PostMapping("/landmarkSub") @PostMapping("/landmarkSub")
public ModelAndView landmarkSent( @ModelAttribute("landmarkData") Landmarks landmarks ) { public ModelAndView landmarkSent(@Valid @ModelAttribute("landmarkData") Landmarks landmarks, BindingResult bindingResult, Model model ) {
System.out.println(landmarks); System.out.println(landmarks);
if (bindingResult.hasErrors()) {
ModelAndView modelAndView = new ModelAndView("Landmarks/LandmarkFormTh.html", model.asMap());
return modelAndView;
} else{
// LandmarksArray userArray = LandmarksArray.getInstance(); // LandmarksArray userArray = LandmarksArray.getInstance();
// Landmarks newUserSubmission = new Landmarks(landmarkData.getFormUsername(),userSubmission.getFormEmail(), // Landmarks newUserSubmission = new Landmarks(landmarkData.getFormUsername(),userSubmission.getFormEmail(),
// userSubmission.getFormPark(), userSubmission.getFormDescription(),userSubmission.getFormCafe(), userSubmission.getFormToilets()); // userSubmission.getFormPark(), userSubmission.getFormDescription(),userSubmission.getFormCafe(), userSubmission.getFormToilets());
...@@ -33,7 +40,11 @@ public class LandmarksController { ...@@ -33,7 +40,11 @@ public class LandmarksController {
// System.out.println(userArray.getFormItems()); // System.out.println(userArray.getFormItems());
// //
ModelAndView modelAndView = new ModelAndView("redirect:/test.html"); ModelAndView modelAndView = new ModelAndView("redirect:/test.html");
return modelAndView; return modelAndView;
}
// return modelAndView;
......
...@@ -5,30 +5,36 @@ ...@@ -5,30 +5,36 @@
<title>Landmark Sign Up</title> <title>Landmark Sign Up</title>
</head> </head>
<body> <body>
<header th:insert="~{/towns/Templating.html :: header}"></header>
<main> <main>
<form action="/landmarkSub" id="landmarkSubmission" name="landmarkSubmission" method="post" th:object="${landmarkData}" onsubmit="return landmarkFormValidation()"> <form action="/landmarkSub" id="landmarkSubmission" name="landmarkSubmission" method="post" th:object="${landmarkData}" onsubmit="return landmarkFormValidation()">
<label>Business Name:&nbsp; <label>Business Name:
<input type="text" th:field="*{landmarkName}"> <input type="text" th:field="*{landmarkName}">
</label><br> </label><br>
<div th:errors="*{landmarkName}" th:if="${#fields.hasErrors('landmarkName')}">ErrorLandmarkName</div>
<label>Contact Address: <label>Contact Address:
<input type="text" th:field="*{landmarkEmail}"> <input type="text" th:field="*{landmarkEmail}">
</label><br> </label><br>
<div th:errors="*{landmarkEmail}" th:if="${#fields.hasErrors('landmarkEmail')}">ErrorEmail</div>
<label>Please Describe Your Business:<br> <label>Please Describe Your Business:<br>
<textarea th:field="*{landmarkDescription}" rows="8" cols="60"></textarea> <textarea th:field="*{landmarkDescription}" rows="8" cols="60"></textarea>
</label><br> </label><br>
<label>Your town/city: <label>Your town/city:
<input type="text" th:field="*{landmarkName}"> <input type="text" th:field="*{landmarkLocation}">
</label><br> </label><br>
<label>Trail: <label>Trail:
<select th:field="*{trailID}"> <select th:field="*{trailID}">
<option value=0 disabled selected>Select Trail</option> <option value=0 disabled selected>Select Trail</option>
<option value=1>Trail 1</option> <option value=1>Trail 1</option>
<option value=2>Trail 2</option> <option value=2>Trail 2</option>
<option value=3>Trail 3</option> <option value=3>Trail 3</option>
</select> </select>
</div>
</label><br> </label><br>
...@@ -38,23 +44,31 @@ ...@@ -38,23 +44,31 @@
</main> </main>
<script> <script>
function landmarkFormValidation(){ function landmarkFormValidation(){
console.log("sadasd");
var pass=true; var pass=true;
var description = (document.forms["landmarkSubmission"]["landmarkDescription"].value); var trail = document.forms["landmarkSubmission"]["trailID"].value
console.log(description); var description = document.forms["landmarkSubmission"]["landmarkDescription"].value;
var descriptionWrdCount=description.split(" ").length var descriptionWrdCount=description.split(" ").length
if(descriptionWrdCount>5){ if (descriptionWrdCount>300){
alert('Please keep your review to a maximum of 5 words.'); alert('Please keep your review to a maximum of 300 words.');
console.log("BAD!!");
pass = false; pass = false;
}
if (trail==0){
alert('Invalid trail selected. \nPlease select the trail you wish to join.');
pass = false;
} }
return pass; return pass;
} }
</script> </script>
<footer th:insert="~{/towns/Templating.html :: footer}"></footer>
</body> </body>
</html> </html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment