mirror of
https://github.com/andrewkdinh/simple-contact.git
synced 2024-11-21 13:34:45 -08:00
Change localStorage to sessionStorage
This commit is contained in:
parent
19fe768aa1
commit
3fe00bfd96
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Extremely simple contact form with a CAPTCHA. Entries are sent to the specified HTTP endpoint.
|
Extremely simple contact form with a CAPTCHA. Entries are sent to the specified HTTP endpoint.
|
||||||
|
|
||||||
JavaScript is not required to fill out the form, but if it is, then form fields are cached in localStorage.
|
JavaScript is not required to fill out the form, but if it is, then form fields are cached in sessionStorage.
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
|
2
main.py
2
main.py
@ -32,7 +32,7 @@ def index():
|
|||||||
message = message.replace("<", "<").replace(">", ">").replace("&", "&")
|
message = message.replace("<", "<").replace(">", ">").replace("&", "&")
|
||||||
if message != "":
|
if message != "":
|
||||||
requests.post(HTTP_ENDPOINT, data={'subject': 'New Simple Contact message', 'message': message})
|
requests.post(HTTP_ENDPOINT, data={'subject': 'New Simple Contact message', 'message': message})
|
||||||
return render_template('message.html', message = "Your message was sent successfully", success=True)
|
return render_template('message.html', message = "Your message was sent successfully")
|
||||||
else:
|
else:
|
||||||
raise TypeError("Invalid method")
|
raise TypeError("Invalid method")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -43,13 +43,13 @@
|
|||||||
Array.from(document.querySelectorAll('form .' + fc)).forEach(element => {
|
Array.from(document.querySelectorAll('form .' + fc)).forEach(element => {
|
||||||
let elementName = fc + '-' + location.pathname + '#' + element.id
|
let elementName = fc + '-' + location.pathname + '#' + element.id
|
||||||
// Load from cache
|
// Load from cache
|
||||||
let cached = localStorage.getItem(elementName)
|
let cached = sessionStorage.getItem(elementName)
|
||||||
if (cached != null) {
|
if (cached != null) {
|
||||||
element.value = cached
|
element.value = cached
|
||||||
}
|
}
|
||||||
// Auto save to cache
|
// Auto save to cache
|
||||||
element.addEventListener('input', function () {
|
element.addEventListener('input', function () {
|
||||||
localStorage.setItem(elementName, element.value)
|
sessionStorage.setItem(elementName, element.value)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})()
|
})()
|
||||||
|
@ -30,12 +30,6 @@
|
|||||||
<a href="/">Go back to homepage</a>
|
<a href="/">Go back to homepage</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if success %}
|
|
||||||
<script>
|
|
||||||
localStorage.clear();
|
|
||||||
</script>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<script defer>
|
<script defer>
|
||||||
let elems = document.getElementsByClassName("script-only");
|
let elems = document.getElementsByClassName("script-only");
|
||||||
elems[0].classList.remove("script-only");
|
elems[0].classList.remove("script-only");
|
||||||
|
Loading…
Reference in New Issue
Block a user