Source:
<code>public String receiveFeedback(HttpServletRequest request, HttpServletResponse response, Model model, @SiteParam Site site, @RequestParam("fromEmailAddress") String fromEmailAddress, @RequestParam("note") String note, @RequestParam("subject") String subject, @RequestParam("name") String name, @RequestParam("userId") String userId, @RequestParam(RECAPTCHA_CHALLENGE_FIELD) String captchaChallenge, @RequestParam(RECAPTCHA_RESPONSE_FIELD) String captchaResponse) throws IOException, MessagingException { validateFeedbackConfig(site); model.addAttribute("fromEmailAddress", fromEmailAddress); model.addAttribute("note", note); model.addAttribute("name", name); model.addAttribute("subject", subject); Set<String> errors = validateInput(fromEmailAddress, note, subject, name); if (!captchaService.validateCaptcha(site, request.getRemoteAddr(), captchaChallenge, captchaResponse)) { errors.add("captchaError"); } if (!errors.isEmpty()) { <START> errors.forEach(error -> model.addAttribute(error, true)); <END> response.setStatus(HttpStatus.BAD_REQUEST.value()); return serveFeedbackPage(model, site); } if (subject.isEmpty()) { model.addAttribute("subject", (String) getFeedbackConfig(site).get("defaultSubject")); } model.addAttribute("id", userId); model.addAttribute("userInfo", formatUserInfo(request)); Multipart content = freemarkerMailService.createContent(site, "feedback", model); String destinationAddress = (String) getFeedbackConfig(site).get("destination"); EmailMessage message = EmailMessage.builder() .addToEmailAddress(EmailMessage.createAddress(null, destinationAddress)) .setSenderAddress(EmailMessage.createAddress(name, fromEmailAddress)) .setSubject(subject) .setContent(content) .setEncoding(freeMarkerConfig.getConfiguration().getDefaultEncoding()) .build(); message.send(javaMailSender); return "redirect:feedback/success"; }</code><technical_language>encapsulate this logic in some kind of method, Wombat Controller superclass a Utility Class. is specific form validation quirks I feel distinction clear. Another good a TODO other form validation this method E.G. email this article</technical_language>

Target:
public String receiveFeedback(HttpServletRequest request, HttpServletResponse response, Model model, @SiteParam Site site, @RequestParam("fromEmailAddress") String fromEmailAddress, @RequestParam("note") String note, @RequestParam("subject") String subject, @RequestParam("name") String name, @RequestParam("userId") String userId, @RequestParam(RECAPTCHA_CHALLENGE_FIELD) String captchaChallenge, @RequestParam(RECAPTCHA_RESPONSE_FIELD) String captchaResponse) throws IOException, MessagingException { enforceDevFeature("feedback"); validateFeedbackConfig(site); model.addAttribute("fromEmailAddress", fromEmailAddress); model.addAttribute("note", note); model.addAttribute("name", name); model.addAttribute("subject", subject); Set<String> errors = validateInput(fromEmailAddress, note, subject, name); if (!captchaService.validateCaptcha(site, request.getRemoteAddr(), captchaChallenge, captchaResponse)) { errors.add("captchaError"); } if (applyValidation(response, model, errors)) { return serveFeedbackPage(model, site); } if (subject.isEmpty()) { model.addAttribute("subject", (String) getFeedbackConfig(site).get("defaultSubject")); } model.addAttribute("id", userId); model.addAttribute("userInfo", formatUserInfo(request)); Multipart content = freemarkerMailService.createContent(site, "feedback", model); String destinationAddress = (String) getFeedbackConfig(site).get("destination"); EmailMessage message = EmailMessage.builder() .addToEmailAddress(EmailMessage.createAddress(null, destinationAddress)) .setSenderAddress(EmailMessage.createAddress(name, fromEmailAddress)) .setSubject(subject) .setContent(content) .setEncoding(freeMarkerConfig.getConfiguration().getDefaultEncoding()) .build(); message.send(javaMailSender); return "redirect:feedback/success"; }