Change localStorage to sessionStorage

main
Andrew Dinh 2 years ago
parent 19fe768aa1
commit 3fe00bfd96
Signed by: andrewkdinh
GPG Key ID: 2B557D93C6C08B86
  1. 2
      README.md
  2. 2
      main.py
  3. 4
      templates/index.html
  4. 6
      templates/message.html

@ -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

@ -32,7 +32,7 @@ def index():
message = message.replace("<", "&lt;").replace(">", "&gt;").replace("&", "&amp;")
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…
Cancel
Save