diff options
author | zzossig <zzossig@gmail.com> | 2020-12-10 00:42:20 +0300 |
---|---|---|
committer | zzossig <zzossig@gmail.com> | 2020-12-10 00:42:20 +0300 |
commit | 7c1c61b6bfafca1f0a1b0c9e2970c044a5d44fbc (patch) | |
tree | de252eb8cad46af273b086e0b6208380863b207f | |
parent | c52fed88df1ba1e79d1f7030235dfdbd1c954c8d (diff) |
Netlify Form support
-rw-r--r-- | layouts/contact/single.html | 2 | ||||
-rw-r--r-- | layouts/partials/contact/netlifyform.html | 39 |
2 files changed, 41 insertions, 0 deletions
diff --git a/layouts/contact/single.html b/layouts/contact/single.html index 5d1326a..07289b9 100644 --- a/layouts/contact/single.html +++ b/layouts/contact/single.html @@ -13,6 +13,8 @@ {{ partial "contact/formspree" . }} {{ else if eq .Params.service "getform" }} {{ partial "contact/getform" . }} + {{ else if eq .Params.service "netlifyform" }} + {{ partial "contact/netlifyform" . }} {{ end }} </div> </main> diff --git a/layouts/partials/contact/netlifyform.html b/layouts/partials/contact/netlifyform.html new file mode 100644 index 0000000..8715161 --- /dev/null +++ b/layouts/partials/contact/netlifyform.html @@ -0,0 +1,39 @@ +<form action={{ $.Param "redirect-after-submit" }} name="contact" method="POST" data-netlify="true" class="contact__form"> + <div class="contact__input--container"> + <div class="contact__input--wrapper"> + <label class="contact__label"> + {{ i18n "contact-name" }} + </label> + <input type="text" name="name" class="contact__input" aria-label="{{ i18n "contact-name" }}"> + </div> + <div class="contact__input--wrapper"> + <label class="contact__label"> + {{ i18n "contact-email" }} + </label> + <input type="email" name="email" class="contact__input" aria-label="{{ i18n "contact-email" }}"> + </div> + </div> + <div class="contact__message--wrapper"> + <label class="contact__label"> + {{ i18n "contact-message" }} + </label> + <textarea name="message" class="contact__message" aria-label="{{ i18n "contact-message" }}"></textarea> + </div> + <input type="submit" value="{{ i18n "contact-send" }}" class="contact__send"> +</form> + +<script> + var formElem = document.querySelector("form"); + formElem.addEventListener("submit", handleSubmit); + + var handleSubmit = function(e) { + e.preventDefault(); + var formData = new FormData(formElem) + fetch('/', { + method: 'POST', + headers: { "Content-Type": "application/x-www-form-urlencoded" }, + body: new URLSearchParams(formData).toString() + }).then(() => console.log('Form successfully submitted')).catch((error) => + alert(error)) + } +</script>
\ No newline at end of file |