adding the local trip form

This commit is contained in:
Chris Cochrun 2024-01-10 10:25:22 -06:00
parent 0c692b3197
commit 9e5acd6aa5
6 changed files with 596 additions and 1 deletions

View file

@ -0,0 +1,16 @@
---
title: Local Mission Trip Form
layout: simple
sharingLinks: false
---
If you'd like to still do a mission trip of some kind, but the other dates do not work for you or you do not feel ready for a longer trip, then this is the trip for you! Sign up here now!
## Mission Trip Agreement
> In order to fill out the application, you must agree to the following!
- I agree to obey all rules and guidelines that TFC Connection and other associated ministries establish, realizing they have my best interest and welfare in mind. I will trust their judgment and obey them. **The staff have the right to confront me if they see a problem in my attitude or in my obeying the rules.**
- I acknowledge that I am expected to do my share of the work on the mission trip and I will be willing to do what is asked of me with an "I'd be glad to" attitude.
- **I will work at making this mission trip a priority!** even if other events come up after I am accepted on a mission trip, I will commit to still go on this trip.
{{< local-trip-form >}}

View file

@ -41,7 +41,7 @@ Its easy to forget just how big Mexico is, and how far our location is from t
## 1-2 Day Local Trip - TBD
Formerly known as the SPLASH trip, this trip will be within 2 hours of the TFC office in Phillipsburg, KS and will be a 2 day trip where you can get a taste for a longer mission trip. If you dont feel ready to go on a longer trip, or have scheduling conflicts with the other trips, this is the trip for you! You will still have the opportunity to serve and grow in your faith in Jesus. Click the button below to sign up for this trip!
{{< button href="/mash-form">}}
{{< button href="/local-trip-form">}}
Local Trip
{{< /button >}}

View file

@ -0,0 +1,241 @@
{{ $formClasses := "bg-neutral-500 text-neutral-50 placeholder-neutral-300 focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 focus:ring-offset-transparent m-2 p-3 rounded-lg hover:bg-neutral-500 checked:text-neutral-500" }}
{{ $requiredField := "<span class='inline-block text-[#f39] text-sm align-super'>* required</span>" }}
<script>
function submitForm(e) {
e.preventDefault();
const form = document.getElementById('form');
const data = new FormData(form);
console.log(data.get("birthdate"));
const birthdate = new Date(data.get("birthdate"));
const age = calculate_age(birthdate);
data.append("age", age);
/* let base = "https://api.tfcconnection.org/local-trip-form"; */
let base = "http://localhost:4242/mt-form";
fetch(base, {
method: "POST",
body: data
}).then((res) => {
console.log(res);
if (res.ok) {
window.location.href = '/mt-health-form?mtregistration=' + "later" +
"&firstName=" + data.get('firstname') +
"&lastName=" + data.get('lastname') +
"&parentFirstName=" + data.get('parentfirstname') +
"&parentLastName=" + data.get('parentlastname') +
"&birthdate=" + data.get('birthdate') +
"&street=" + data.get('street') +
"&city=" + data.get('city') +
"&state=" + data.get('state') +
"&zip=" + data.get('zip') +
"&parentPhone=" + data.get('parentphone');
console.log(res);
}
});
}
function calculate_age(dob) {
var diff_ms = Date.now() - dob.getTime();
var age_dt = new Date(diff_ms);
return Math.abs(age_dt.getUTCFullYear() - 1970);
}
function process() {
var studentAgree = document.getElementById("student-agree").checked;
console.log(studentAgree);
var parentAgree = document.getElementById("adult-agree").checked;
console.log(parentAgree);
if (studentAgree && parentAgree) {
document.getElementById('mt-form').hidden = false
console.log("WOOHOO");
}
else {
document.getElementById('form').hidden = true
document.getElementById('mt-form').hidden = true
console.log("NEGATORY");
}
}
document.addEventListener('DOMContentLoaded', process);
</script>
<div class="m-4">
<div class="p-2">
<input type="checkbox" name="student-agree" id="student-agree"
onclick="process()" class="form-checkbox {{ $formClasses }}" />
<label for="student-agree">I agree to the above</label>
</div>
<div class="p-2">
<input type="checkbox" name="adult-agree" id="adult-agree"
onclick="process()" class="form-checkbox {{ $formClasses }}" />
<label for="adult-agree">Parent agrees to the above</label>
</div>
</div>
<div id="mt-form" class="form text-lg w-full">
<form id='form' onsubmit="submitForm(event)" autocomplete="on" method="post" target="_parent" class="w-full items-center flex flex-wrap">
<h3 class="basis-full">Mission Trip Application</h3>
<div class="basis-full flex flex-wrap my-4">
<label for="firstname" class="basis-full mx-2">What is your first and last name?</label>
<br/>
<input type="text" id="firstname" name="firstname"
placeholder="First Name" class="flex-1 form-input {{ $formClasses }}">
<input type="text" id="lastname" name="lastname"
placeholder="Last Name" class="flex-1 form-input {{ $formClasses }}">
</div>
<div class="basis-full flex flex-wrap my-4">
<label for="parentfirstname" class="basis-full mx-2">What is your parent's first and last name?</label>
<input type="text" id="parentfirstname" name="parentfirstname"
class="flex-1 form-input {{ $formClasses }}"
placeholder="First Name">
<input type="text" id="parentlastname" name="parentlastname"
class="flex-1 form-input {{ $formClasses }}"
placeholder="Last Name">
</div>
<div class="basis-full my-4">
<div class="">
<label for="birthdate" class="">When were you born?</label>
<input type="date" id="birthdate" name="birthdate"
class="form-date {{ $formClasses }}">
</div>
<div class="">
<label for="gender" class="">Gender</label>
<select id="gender" name="gender" class="form-select {{ $formClasses }}">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
</div>
<div class="basis-full flex flex-wrap my-4">
<label for="street" class="basis-full mx-2">What is your address? <span class='inline-block text-[#f39] text-sm align-middle'>* required</span></label>
<input type="text" id="street" name="street"
class="basis-full form-input {{ $formClasses }}"
placeholder="Street Address" required>
<input type="text" id="city" name="city"
class="basis-full form-input {{ $formClasses }}"
placeholder="City" required>
<input type="text" id="state" name="state"
class="flex-auto form-input {{ $formClasses }}"
placeholder="State" required>
<input type="text" id="zip" name="zip"
class="flex-auto form-input {{ $formClasses }}"
placeholder="Zip Code" required>
</div>
<div class="flex-auto flex flex-wrap items-center">
<label for="cellphone" class="basis-1/4 mr-4">Cell phone</label>
<input type="tel" id="cellphone" name="cellphone"
class="flex-auto form-input {{ $formClasses }}">
</div>
<div class="flex-auto flex flex-wrap items-center">
<label for="parentphone" class="basis-1/4 mr-4">Parent phone</label>
<input type="tel" id="parentphone" name="parentphone"
class="flex-auto form-input {{ $formClasses }}">
</div>
<div class="basis-full flex items-center">
<label for="email" class="basis-1/4 mr-4">Email</label>
<input type="email" id="email" name="email"
pattern="^[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*@[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*$"
class="basis-3/4 form-input {{ $formClasses }}">
</div>
<div class="basis-full flex items-center">
<label for="parentemail" class="basis-1/4 mr-4">Parent's email?</label>
<input type="email" id="parentemail" name="parentemail"
pattern="^[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*@[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*$"
class="basis-3/4 form-input {{ $formClasses }}">
</div>
<label for="school" class="basis-full mx-2 mt-12">What school do you go to?</label>
<input type="text" id="school" name="school" class="basis-full form-input {{ $formClasses }}">
<div class="basis-full my-4">
<label for="grade" class=" mx-2">Grade</label>
<br/>
<input type="radio" id="grade" name="grade" value="8"
class="form-input {{ $formClasses }}" checked>
<label for="grade" class="">8th</label>
<br/>
<input type="radio" id="grade" name="grade" value="freshman"
class="form-input {{ $formClasses }}">
<label for="grade" class="">Freshman</label>
<br/>
<input type="radio" id="grade" name="grade" value="sophomore"
class="form-input {{ $formClasses }}">
<label for="grade" class="">Sophomore</label>
<br/>
<input type="radio" id="grade" name="grade" value="junior"
class="form-input {{ $formClasses }}">
<label for="grade" class="">Junior</label>
<br/>
<input type="radio" id="grade" name="grade" value="senior"
class="form-input {{ $formClasses }}">
<label for="grade" class="">Senior</label>
</div>
<div class="basis-full flex flex-wrap my-4">
<label for="pastorfirstname" class="basis-full mx-2">What is your pastor's name and number?</label>
<input type="text" id="pastorfirstname" name="pastorfirstname"
class="flex-auto form-input {{ $formClasses }}"
placeholder="First Name">
<input type="text" id="pastorlastname" name="pastorlastname"
class="flex-auto form-input {{ $formClasses }}"
placeholder="Last Name">
<input type="tel" id="pastorphone" name="pastorphone"
class="flex-auto form-input {{ $formClasses }}"
placeholder="Phone Number">
</div>
<div class="basis-full my-4 flex flex-wrap items-center">
<label for="church" class="basis-full mx-2">What church do you attend?</label>
<input type="text" id="church" name="church"
class="basis-full form-input {{ $formClasses }}">
<label for="churchattendance" class="basis-full mt-8 mx-2">Do you attend church regularly? <code id="layout" class="inline-block text-secondary-500">Regularly being 3 times a month</code></label>
<div class="basis-full flex flex-wrap items-center">
<input type="radio" id="churchattendance" name="churchattendance"
value="yes" class="flex-none form-input {{ $formClasses }}" checked>
<label for="churchattendance" class="flex-auto">Yes</label>
</div>
<div class="basis-full flex flex-wrap items-center">
<input type="radio" id="churchattendance" name="churchattendance"
value="no" class="flex-none form-input {{ $formClasses }}">
<label for="churchattendance" class="flex-auto">No</label>
</div>
<div class="basis-full flex flex-wrap items-center">
<input type="radio" id="churchattendance" name="churchattendance"
value="other" class="flex-none form-input {{ $formClasses }}">
<input type="text" id="churchattendanceother" name="churchattendanceother"
class="flex-auto form-input {{ $formClasses }}" placeholder="Other">
</div>
</div>
<div class="basis-full flex flex-wrap my-4">
<div class="basis-1/2 flex flex-wrap items-center">
<label for="tfcgroup" class="flex-initial">TFC Group</label>
<select id="tfcgroup" name="tfcgroup" class="flex-auto form-select {{ $formClasses }}">
<option value="Phillipsburg">Phillipsburg</option>
<option value="Atwood">Atwood</option>
<option value="Northern Valley">Northern Valley</option>
<option value="Southern Valley">Southern Valley</option>
<option value="Thunder Ridge">Thunder Ridge</option>
<option value="Logan">Logan</option>
<option value="Wakeeney">Wakeeney</option>
<option value="Codell">Codell</option>
<option value="Colby">Colby</option>
</select>
</div>
<div class="basis-1/2 flex flex-wrap items-center">
<label for="shirt" class="flex-initial">T-Shirt Size</label>
<select id="shirt" name="shirt" class="flex-auto form-select {{ $formClasses }}">
<option value="small">Small</option>
<option value="medium">Medium</option>
<option value="large">Large</option>
<option value="xl">XL</option>
<option value="xxl">2XL</option>
<option value="xxxl">3XL</option>
</select>
</div>
</div>
<div class="basis-full mt-8">
<button type="submit" class="content-right rounded-lg bg-primary-700 h-12 w-24 focus:bg-primary-900 focus:ring focus:ring-primary-700 hover:bg-primary-900 float-right">Submit</button>
</div>
</form>
</div>

335
src/api/local_trip_form.rs Normal file
View file

@ -0,0 +1,335 @@
use actix_multipart::form::{text::Text, MultipartForm};
use actix_web::{post, HttpResponse};
use lettre::{
message::MultiPart,
transport::smtp::authentication::{Credentials, Mechanism},
Message, SmtpTransport, Transport,
};
#[derive(Debug, MultipartForm, Default)]
struct LocalForm {
#[multipart(rename = "firstname")]
first_name: Option<Text<String>>,
#[multipart(rename = "lastname")]
last_name: Option<Text<String>>,
#[multipart(rename = "parentfirstname")]
parent_first_name: Option<Text<String>>,
#[multipart(rename = "parentlastname")]
parent_last_name: Option<Text<String>>,
birthdate: Option<Text<String>>,
gender: Option<Text<String>>,
street: Option<Text<String>>,
city: Option<Text<String>>,
state: Option<Text<String>>,
zip: Option<Text<i32>>,
cellphone: Option<Text<String>>,
parentphone: Option<Text<String>>,
email: Option<Text<String>>,
parentemail: Option<Text<String>>,
school: Option<Text<String>>,
grade: Option<Text<String>>,
#[multipart(rename = "pastorfirstname")]
pastor_first_name: Option<Text<String>>,
#[multipart(rename = "pastorlastname")]
pastor_last_name: Option<Text<String>>,
#[multipart(rename = "churchattendance")]
church_attendance: Option<Text<String>>,
#[multipart(rename = "tfcgroup")]
tfc_group: Option<Text<String>>,
shirt: Option<Text<String>>,
}
#[post("/local-trip-form")]
pub async fn local_form(MultipartForm(form): MultipartForm<LocalForm>) -> HttpResponse {
let first = form
.first_name
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
let last = form
.last_name
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
let email_subject = format!("{} {} signed up for the local mission trip!", first, last);
let parent = format!(
"{} {}",
form.parent_first_name
.as_ref()
.unwrap_or(&Text {
0: String::from("")
})
.0
.clone(),
form.parent_last_name
.as_ref()
.unwrap_or(&Text {
0: String::from("")
})
.0
.clone()
);
let birthdate = form
.birthdate
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
let gender = form
.gender
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
let street = form
.street
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
let city = form
.city
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
let state = form
.state
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
let zip = form.zip.as_ref().unwrap_or(&Text { 0: 0 }).0.clone();
let cellphone = form
.cellphone
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
let parentphone = form
.parentphone
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
let email = form
.email
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
let parentemail = form
.parentemail
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
let school = form
.school
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
let grade = form
.grade
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
let pastor = format!(
"{} {}",
form.pastor_first_name
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone(),
form.pastor_last_name
.as_ref()
.unwrap_or(&Text {
0: String::from("")
})
.0
.clone()
);
let church_attendance = form
.church_attendance
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
let tfc_group = form
.tfc_group
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
let shirt = form
.shirt
.as_ref()
.unwrap_or(&Text {
0: String::from(""),
})
.0
.clone();
log::info!("{first} {last} signed up for the local mission trip!");
let email = markup::new! {
@markup::doctype()
html {
head {
title { @format!("{} {} signed up for the local mission trip!", first, last) }
style {
"table { border-collapse: collapse; width: 100% }"
"td, th { padding: 8px }"
"td { text-align: left; width: 70%; word-wrap: break-word }"
"th { text-align: right; border-right: 1px solid #ddd }"
"tr { border-bottom: 1px solid #ddd }"
"h1 { text-align: center }"
}
}
body {
h1 { @format!("Mission trip form for {} {}!", first, last) }
hr;
table {
tr {
th { "Name" }
td { @format!("{} {}", first, last) }
}
tr {
th { "Parent" }
td { @parent }
}
tr {
th { "Birthdate" }
td { @birthdate }
}
tr {
th { "Gender" }
td { @gender }
}
tr {
th { "Street" }
td { @street }
}
tr {
th { "City" }
td { @city }
}
tr {
th { "State" }
td { @state }
}
tr {
th { "Zip" }
td { @zip }
}
tr {
th { "Phone" }
td { @cellphone }
}
tr {
th { "Parent Phone" }
td { @parentphone }
}
tr {
th { "Email" }
td { @email }
}
tr {
th { "Parent Email" }
td { @parentemail }
}
tr {
th { "School" }
td { @school }
}
tr {
th { "Grade" }
td { @grade }
}
tr {
th { "Pastor" }
td { @pastor }
}
tr {
th { "Church Attendance" }
td { @church_attendance }
}
tr {
th { "TFC Group" }
td { @tfc_group }
}
tr {
th { "T-Shirt Size" }
td { @shirt }
}
}
}
}
};
log::info!("{:?}", form);
let multi = MultiPart::alternative_plain_html(String::from("Testing"), email.to_string());
if let Ok(m) = Message::builder()
.from(
"TFC ADMIN <no-reply@mail.tfcconnection.org>"
.parse()
.unwrap(),
)
.to("Chris Cochrun <chris@tfcconnection.org>".parse().unwrap())
.to("Ethan Rose <ethan@tfcconnection.org>".parse().unwrap())
.subject(email_subject)
.multipart(multi)
{
let sender = SmtpTransport::relay("mail.tfcconnection.org")
.ok()
.unwrap()
.credentials(Credentials::new(
"no-reply@mail.tfcconnection.org".to_owned(),
"r9f36mNZFtiW4f".to_owned(),
))
.authentication(vec![Mechanism::Plain])
.build();
match sender.send(&m) {
Ok(res) => log::info!("{:?}", res),
Err(e) => log::info!("{e}"),
}
} else {
log::info!("Email incorrect");
}
HttpResponse::Ok().body("thankyou")
}

View file

@ -1,5 +1,6 @@
pub mod church_form;
pub mod health_form;
pub mod local_trip_form;
pub mod mt_form;
pub mod parent_form;
pub mod teacher_form;

View file

@ -6,6 +6,7 @@ use actix_multipart::form::tempfile::TempFileConfig;
use actix_web::{middleware, App, HttpServer};
use api::church_form::church_form;
use api::health_form::health_form;
use api::local_trip_form::local_form;
use api::mt_form::mt_form;
use api::parent_form::parent_form;
use api::teacher_form::teacher_form;
@ -46,6 +47,7 @@ async fn main() -> std::io::Result<()> {
.service(parent_form)
.service(teacher_form)
.service(church_form)
.service(local_form)
})
.bind(("127.0.0.1", 4242))?
.workers(2)