diff options
author | Vittorio Alfieri <vittorio88@gmail.com> | 2019-04-09 22:37:12 +0300 |
---|---|---|
committer | Guillermo Guerrero Ibarra <wolf.fox1985@gmail.com> | 2019-04-09 22:37:12 +0300 |
commit | cd3401ad5d6d18539a04d8a4aa260ca9db4113ef (patch) | |
tree | 0263e725ccf49437e4e34da3850ddd3a71036b01 | |
parent | 25e51a9385c35bad02d9c8da61e8d7e152cbba6c (diff) |
Fix formspree. Add possibility to send request through plain HTTP POST (#203)
* Fix formspree. Add possibility to send request through plain HTTP POST or ajax with toggle.
* Fix formspree. Add possibility to send request through plain HTTP POST or ajax with toggle. Improve hugo templating in contact.html
* Fix formspree. Add possibility to send request through plain HTTP POST or ajax with toggle. Add toggle to exampleSite/config.toml
* Fix formspree. Add possibility to send request through plain HTTP POST or ajax with toggle. Remove useless function.
* Fix formspree. Add possibility to send request through plain HTTP POST or ajax with toggle. Use custom class only for ajax.
* Fix formspree. Add possibility to send request through plain HTTP POST or ajax with toggle. Return if form is null.
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | exampleSite/config.toml | 1 | ||||
-rw-r--r-- | layouts/partials/contact.html | 2 | ||||
-rw-r--r-- | static/js/front.js | 7 |
4 files changed, 8 insertions, 5 deletions
@@ -140,11 +140,12 @@ You can optionally add the google maps widget defining latitude and longitude in Since this Hugo sites are static, the contact form uses [Formspree](https://formspree.io/) as a proxy. The form makes a POST request to their servers to send the actual email. Visitors can send up to a 1000 emails each month for free. -To enable the form in the contact page, just type your Formspree email in the `config.toml` file. +To enable the form in the contact page, just type your Formspree email in the `config.toml` file, and specify whether to use ajax(paid) to send request or plain HTTP POST(free). ```yaml [params] email = "your@email.com" +contact_form_ajax = false ``` ### Menu diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 0d53d69..6653731 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -90,6 +90,7 @@ paginate = 10 # # Enable the contact form by entering your Formspree.io email email = "your@email.com" + contact_form_ajax = false about_us = "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>" copyright = "Copyright (c) 2015 - 2016, YourCompany; all rights reserved." diff --git a/layouts/partials/contact.html b/layouts/partials/contact.html index af97f15..96c89f0 100644 --- a/layouts/partials/contact.html +++ b/layouts/partials/contact.html @@ -15,7 +15,7 @@ <div id="contact-message"></div> - <form class="contact-form" method="post" action="https://formspree.io/{{ .Site.Params.email }}"> + <form {{ with .Site.Params.contact_form_ajax }}class="contact-form-ajax"{{ else }}{{ end }} method="post" action="https://formspree.io/{{ .Site.Params.email }}"> <div class="row"> <div class="col-sm-6"> <div class="form-group"> diff --git a/static/js/front.js b/static/js/front.js index 9e62ae7..14ee525 100644 --- a/static/js/front.js +++ b/static/js/front.js @@ -19,12 +19,13 @@ $(function () { animations()
counters()
demo()
- contactForm()
+ contactFormAjax()
})
// Ajax contact
-function contactForm () {
- var form = $('.contact-form')
+function contactFormAjax () {
+ var form = $('.contact-form-ajax')
+ if (typeof form === 'undefined') return false
form.submit(function () {
$this = $(this)
$.post($(this).attr('action'),
|