From c624b64407e929e968f6b04e18d3e395184d48ca Mon Sep 17 00:00:00 2001
From: everettb <everettb@msu.edu>
Date: Mon, 28 Oct 2019 16:03:16 -0400
Subject: [PATCH] fix bug in 4h forms

- double quote around vars
- response.redirect doesn't function unless at very top of page... so moved messages to accomodate.
---
 4h-joinForm.vtl      | 24 +++++++++---------------
 4h-volunteerForm.vtl | 18 +++++++-----------
 2 files changed, 16 insertions(+), 26 deletions(-)

diff --git a/4h-joinForm.vtl b/4h-joinForm.vtl
index 8f25ced..5ff6a81 100644
--- a/4h-joinForm.vtl
+++ b/4h-joinForm.vtl
@@ -9,6 +9,8 @@
 #set($captchaStatus = $UtilMethods.xmlEscape($request.getParameter("captcha")))
 #set($status = $UtilMethods.xmlEscape($request.getParameter("status")))
 
+<h2 id="4h">Connect with 4-H in your county!</h2>
+
 #set($gRecaptchaResponse = $UtilMethods.xmlEscape($request.getParameter("g-recaptcha-response")))
 
 #if($UtilMethods.isSet($status))
@@ -22,33 +24,25 @@
         #set($subject = "4-H Sign Up")
         ## get county page from identifier to pull title (in message) and email (to field) below
         #set($countyPage = $dotcontent.find($county))
+        <!-- <p>${countyPage.email}</p> -->
         #set($message = "This person filled out a form on the 4-H website indicating that they would like to become a member! <br><br> Parent or Guardian: ${parentGuardian}<br> Email: ${email} <br> Phone: ${phone} <br> County: ${countyPage.title} <br> 4-H'er Name: $!{name} <br> 4-H'er Age: $!{age}")
 
-        #set($error = $mailer.sendEmail('${countyPage.email}, weichel@anr.msu.edu', 'noreply@anr.msu.edu', ${subject}, $message, true))
+        #set($error = $mailer.sendEmail("${countyPage.email}, weichel@anr.msu.edu", "noreply@anr.msu.edu", ${subject}, $message, true))
 
 		#if($UtilMethods.isSet($error))
 			<div class="callout alert"><p>Please fix the following error(s): $error</p></div>
 		#else
-            $response.sendRedirect("${VTLSERVLET_URI}?captcha=pass")
-            #stop
+            <h3>Thank You!</h3>
+            <p>Someone will contact you soon about joining 4-H in the county you selected.</p>
 		#end
     #else
         ##fail
-        $response.sendRedirect("${VTLSERVLET_URI}?captcha=fail&parentGuardian=$!{parentGuardian}&email=$!{email}&phone=$!{phone}&county=$!{county}&name=$!{name}&age=$!{age}")
+        $response.sendRedirect("https://${request.serverName}${VTLSERVLET_URI}?captcha=fail&parentGuardian=$!{parentGuardian}&email=$!{email}&phone=$!{phone}&county=$!{county}&name=$!{name}&age=$!{age}")
         #stop
+            <div class="callout alert" style="padding:0 1em;"><p>Please fill out captcha</p></div>
     #end
 #end
-
-<h2>Connect with 4-H in your county!</h2>
-#if($captchaStatus == "fail")
-    <div class="callout alert" style="padding:0 1em;"><p>Please fill out captcha</p></div>
-#end
-#if($captchaStatus == "pass")
-    <h3>Thank You!</h3>
-    <p>Someone will contact you soon about joining 4-H in the county you selected.</p>
-#end
-
-<form class="" action="$VTLSERVLET_URI?status=submit" method="post">
+<form class="" action="$VTLSERVLET_URI?status=submit#4h" method="post">
     <p>
         <label for="parentGuardian">Parent/ Guardian</label>
         <input type="text" required name="parentGuardian" value="$!{parentGuardian}">
diff --git a/4h-volunteerForm.vtl b/4h-volunteerForm.vtl
index 5106ac9..37f4698 100644
--- a/4h-volunteerForm.vtl
+++ b/4h-volunteerForm.vtl
@@ -7,6 +7,8 @@
 #set($captchaStatus = $UtilMethods.xmlEscape($request.getParameter("captcha")))
 #set($status = $UtilMethods.xmlEscape($request.getParameter("status")))
 
+<h2 id="4h">Become a 4-H volunteer!</h2>
+
 #set($gRecaptchaResponse = $UtilMethods.xmlEscape($request.getParameter("g-recaptcha-response")))
 
 #if($UtilMethods.isSet($status))
@@ -20,31 +22,25 @@
         ## get county page from identifier to pull title (in message) and email (to field) below
         #set($countyPage = $dotcontent.find($county))
         #set($message = "This person filled out a form on the 4-H website indicating that they would like to become a volunteer! <br> Name: ${name}<br> Email: ${email} <br> Phone: ${phone} <br> County: ${countyPage.title}")
-        #set($error = $mailer.sendEmail('${countyPage.email}, weichel@anr.msu.edu', 'noreply@anr.msu.edu', ${subject}, $message, true))
+        #set($error = $mailer.sendEmail("${countyPage.email}, weichel@anr.msu.edu", "noreply@anr.msu.edu", ${subject}, $message, true))
 
 		#if($UtilMethods.isSet($error))
 			<div class="callout alert"><p>Please fix the following error(s): $error</p></div>
 		#else
             $response.sendRedirect("${VTLSERVLET_URI}?captcha=pass")
             #stop
+            <h3>Thank You!</h3>
+            <p>Someone from the county you have selected will contact you about enrollment.</p>
 		#end
     #else
         ##fail
         $response.sendRedirect("${VTLSERVLET_URI}?captcha=fail&name=$!{name}&email=$!{email}&phone=$!{phone}&county=$!{county}")
         #stop
+        <div class="callout alert" style="padding:0 1em;"><p>Please fill out captcha</p></div>
     #end
 #end
 
-<h2>Become a 4-H volunteer!</h2>
-#if($captchaStatus == "fail")
-    <div class="callout alert" style="padding:0 1em;"><p>Please fill out captcha</p></div>
-#end
-#if($captchaStatus == "pass")
-    <h3>Thank You!</h3>
-    <p>Someone from the county you have selected will contact you about enrollment.</p>
-#end
-
-<form class="" action="$VTLSERVLET_URI?status=submit" method="post">
+<form class="" action="$VTLSERVLET_URI?status=submit#4h" method="post">
     <p>
         <label for="name">Name</label>
         <input type="text" required name="name" value="$!{name}">
-- 
GitLab