Add name saving to resolve #7
This commit is contained in:
parent
a93df189d6
commit
15d7533ffe
|
@ -32,7 +32,7 @@
|
||||||
<h1><script>
|
<h1><script>
|
||||||
document.write(qp.action + " " + qp.room)
|
document.write(qp.action + " " + qp.room)
|
||||||
</script></h1>
|
</script></h1>
|
||||||
<form action="#">
|
<form>
|
||||||
<label>
|
<label>
|
||||||
Full Name:<br>
|
Full Name:<br>
|
||||||
<input type="text" name="name" id="name" required>
|
<input type="text" name="name" id="name" required>
|
||||||
|
@ -45,22 +45,32 @@
|
||||||
</form>
|
</form>
|
||||||
</main>
|
</main>
|
||||||
<script>
|
<script>
|
||||||
|
// Prefill the name field if it was successfully entered before
|
||||||
|
var savedName = localStorage.getItem('name')
|
||||||
|
if (savedName)
|
||||||
|
document.getElementById('name').value = savedName
|
||||||
|
|
||||||
form = document.querySelector('form')
|
form = document.querySelector('form')
|
||||||
form.onsubmit= function(e) {
|
form.onsubmit= function(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
console.log(e)
|
console.log(e)
|
||||||
|
|
||||||
|
var name = e.srcElement[0].value
|
||||||
|
var agreed = e.srcElement[1].checked
|
||||||
|
|
||||||
var payload = (qp.action == 'arrival') ?
|
var payload = (qp.action == 'arrival') ?
|
||||||
{
|
{
|
||||||
'room': qp.room,
|
'room': qp.room,
|
||||||
'name': e.srcElement[0].value,
|
'name': name,
|
||||||
'agreetoguidelines': e.srcElement[1].checked
|
'agreetoguidelines': agreed
|
||||||
} :
|
} :
|
||||||
{
|
{
|
||||||
'name': e.srcElement[0].value,
|
'name': name,
|
||||||
'cleanedworkspace': e.srcElement[1].checked
|
'cleanedworkspace': agreed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(payload)
|
||||||
|
|
||||||
fetch("/" + qp.action, {
|
fetch("/" + qp.action, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(payload)
|
body: JSON.stringify(payload)
|
||||||
|
@ -69,6 +79,7 @@
|
||||||
if (Math.floor(res.status / 100) == 2) {
|
if (Math.floor(res.status / 100) == 2) {
|
||||||
|
|
||||||
form.innerHTML = "<h2>Done. Thanks!</h2>"
|
form.innerHTML = "<h2>Done. Thanks!</h2>"
|
||||||
|
localStorage.setItem('name', name)
|
||||||
|
|
||||||
} else if (res.status == 409) {
|
} else if (res.status == 409) {
|
||||||
|
|
||||||
|
@ -87,8 +98,6 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(payload)
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in New Issue