feat: add working privacy policy contact form

This commit is contained in:
Oliver Booth 2023-09-24 00:04:44 +01:00
parent 5283985026
commit 3076f58485
Signed by: oliverbooth
GPG Key ID: E60B570D1B7557B5
2 changed files with 37 additions and 10 deletions

View File

@ -31,6 +31,33 @@ public class ContactController : Controller
return RedirectToPage("/Contact/Index");
}
[HttpPost("privacy-policy")]
public async Task<IActionResult> HandlePrivacyPolicy()
{
if (!Request.HasFormContentType)
{
return RedirectToPage("/Contact/Privacy");
}
IFormCollection form = Request.Form;
StringValues name = form["name"];
StringValues email = form["email"];
StringValues subject = form["subject"];
StringValues message = form["message"];
StringValues privacyPolicy = form["privacy-policy"];
await using SmtpSender sender = CreateSender();
await sender.WriteEmail
.To("Oliver Booth", _destination.GetValue<string>("PrivacyPolicy"))
.From(name, email)
.Subject($"[{privacyPolicy}] {subject}")
.BodyHtml(message)
.SendAsync();
TempData["Success"] = true;
return RedirectToPage("/Contact/Result");
}
[HttpPost("other")]
public async Task<IActionResult> HandleMiscellaneous()
{

View File

@ -18,21 +18,21 @@
Please outline your concerns in the form below, and I will get back to you as soon as possible.
</p>
<form method="post">
<form method="post" asp-controller="Contact" asp-action="HandlePrivacyPolicy">
<input type="hidden" name="contact-type" value="privacy-policy">
<div class="form-group" style="margin-top: 10px;">
<label for="your-name">Your Name</label>
<input type="text" class="form-control" id="your-name" name="your-name" placeholder="Who are you?">
<label for="name">Your Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Who are you?">
</div>
<div class="form-group" style="margin-top: 10px;">
<label for="your-email">Your Email Address</label>
<input type="email" class="form-control" id="your-email" name="your-email" placeholder="How can I reach you?">
<label for="email">Your Email Address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="How can I reach you?">
</div>
<div class="form-group" style="margin-top: 10px;">
<label for="your-email">Privacy Policy</label>
<label for="privacy-policy">Privacy Policy</label>
<select name="privacy-policy" class="form-control" id="privacy-policy">
<option value="website" selected="@(Model.Which != "google-play")">This website's policy</option>
<option value="google-play" selected="@(Model.Which == "google-play")">Google Play policy</option>
@ -40,13 +40,13 @@
</div>
<div class="form-group" style="margin-top: 10px;">
<label for="position-title">Subject Matter</label>
<input type="text" class="form-control" id="position-title" name="position-title" placeholder="Describe your concerns here in a few words" maxlength="100">
<label for="subject">Subject</label>
<input type="text" class="form-control" id="subject" name="subject" placeholder="Describe your concerns here in a few words" maxlength="100">
</div>
<div class="form-group" style="margin-top: 10px;">
<label for="position-description">Description</label>
<textarea class="form-control" id="position-description" name="position-description" rows="5" required placeholder="Go into detail about the nature of your concerns."></textarea>
<label for="message">Description</label>
<textarea class="form-control" id="message" name="message" rows="5" required placeholder="Go into detail about the nature of your concerns."></textarea>
</div>
<button type="submit" class="btn btn-primary" style="margin-top: 10px;">Submit</button>