mirror of
https://github.com/andrewkdinh/simple-contact.git
synced 2024-11-23 00:04:41 -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.
|
||||
|
||||
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
|
||||
|
||||
|
2
main.py
2
main.py
@ -32,7 +32,7 @@ def index():
|
||||
message = message.replace("<", "<").replace(">", ">").replace("&", "&")
|
||||
if 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:
|
||||
raise TypeError("Invalid method")
|
||||
except Exception as e:
|
||||
|
@ -43,13 +43,13 @@
|
||||
Array.from(document.querySelectorAll('form .' + fc)).forEach(element => {
|
||||
let elementName = fc + '-' + location.pathname + '#' + element.id
|
||||
// Load from cache
|
||||
let cached = localStorage.getItem(elementName)
|
||||
let cached = sessionStorage.getItem(elementName)
|
||||
if (cached != null) {
|
||||
element.value = cached
|
||||
}
|
||||
// Auto save to cache
|
||||
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>
|
||||
{% endif %}
|
||||
|
||||
{% if success %}
|
||||
<script>
|
||||
localStorage.clear();
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
<script defer>
|
||||
let elems = document.getElementsByClassName("script-only");
|
||||
elems[0].classList.remove("script-only");
|
||||
|
Loading…
Reference in New Issue
Block a user