You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
3.3 KiB
130 lines
3.3 KiB
<script>
|
|
import { variables } from "$lib/helpers/variables";
|
|
|
|
let email = "";
|
|
let message = "";
|
|
let notify;
|
|
let error;
|
|
|
|
const validateEmail = (email) => {
|
|
return String(email)
|
|
.toLowerCase()
|
|
.match(
|
|
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
);
|
|
};
|
|
|
|
$: allowSend = validate(email, message);
|
|
|
|
function validate(email, message) {
|
|
if(email == "" || message == "") {
|
|
error = null;
|
|
return false;
|
|
}
|
|
|
|
if(!validateEmail(email)) {
|
|
error = "Invalid email format!";
|
|
return false;
|
|
}
|
|
|
|
if(message.length < 10) {
|
|
error = "Message body too short!";
|
|
return false;
|
|
}
|
|
|
|
error = null;
|
|
return true;
|
|
}
|
|
|
|
function send() {
|
|
email = "";
|
|
message = "";
|
|
notify = "Email sent!";
|
|
return;
|
|
}
|
|
</script>
|
|
|
|
<main class="flex flex-col gap-5">
|
|
<form
|
|
class="flex flex-col gap-5"
|
|
action="https://api.staticforms.xyz/submit"
|
|
method="post"
|
|
>
|
|
<input
|
|
type="hidden"
|
|
name="accessKey"
|
|
value="534c3443-4fa9-41bc-976b-684b3049bef3"
|
|
/>
|
|
<input type="text" name="honeypot" style="display: none;" />
|
|
<input type="hidden" name="redirectTo" value={variables.appUrl + "/contact"} />
|
|
|
|
<div class="flex flex-col">
|
|
<label for="email" value="E-Mail" class="text-lg font-bold"
|
|
>E-Mail</label
|
|
>
|
|
<input
|
|
id="email"
|
|
name="email"
|
|
type="text"
|
|
class="text-lg py-1 px-2 rounded-lg shadow bg-gray-600"
|
|
bind:value={email}
|
|
/>
|
|
</div>
|
|
|
|
<div class="flex flex-col">
|
|
<label for="message" value="E-Mail" class="text-lg font-bold"
|
|
>Message</label
|
|
>
|
|
<textarea
|
|
id="message"
|
|
name="message"
|
|
class="text-lg py-1 px-2 rounded-lg shadow bg-gray-600"
|
|
bind:value={message}
|
|
rows="5"
|
|
/>
|
|
</div>
|
|
|
|
<div class="flex flex-col">
|
|
{#if allowSend}
|
|
<button
|
|
type="submit"
|
|
class="bg-gradient-to-tr from-red-500 to-pink-500 py-2 px-3 rounded-lg font-bold shadow button"
|
|
>Send</button
|
|
>
|
|
{:else}
|
|
<button
|
|
disabled
|
|
type="none"
|
|
title="Fill in the fields before submitting"
|
|
class="bg-black bg-opacity-50 py-2 px-3 rounded-lg font-bold shadow text-gray-400"
|
|
>
|
|
Send
|
|
</button>
|
|
{/if}
|
|
</div>
|
|
|
|
{#if notify}
|
|
<p class="text-green-500 font-bold text-lg">{notify}</p>
|
|
{/if}
|
|
{#if error != undefined && error != null}
|
|
<p class="text-red-500 font-bold text-lg">{error}</p>
|
|
{/if}
|
|
</form>
|
|
</main>
|
|
|
|
<style>
|
|
.button {
|
|
transition-duration: 0.3s;
|
|
}
|
|
|
|
.button:hover {
|
|
transition-duration: 0.3s;
|
|
transform: translateY(-2px);
|
|
}
|
|
|
|
.button:active {
|
|
transition-duration: 0.3s;
|
|
transform: translateY(5px);
|
|
}
|
|
</style>
|