async function _submit(event, element) { event.preventDefault(); /* debug */ console.log(`submitting form:`); console.log(element) console.log(`destination: ${element.action}`); const formdata = new FormData(element); console.log(`data:`); console.log(formdata); try { await fetch(element.action, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded", }, body: new URLSearchParams(new FormData(element)), }).then(async response => { console.log(response); const ok = response.status == 200; const text = await response.text(); notify(text, ok ? 'ok' : 'error'); /* /static/js/notify.js */ if (ok) { if (element.hasAttribute("beep-redirect")) window.location.href = element.getAttribute("beep-redirect"); else if (element.hasAttribute('beep-redirect-js')) window.location.href = eval(element.getAttribute("beep-redirect-js"))( response, text ); } }); } catch (error) { console.error(error.message); } } const e = document.getElementsByTagName('form'); for (let i = 0 ; i < e.length ; i++) { const element = e.item(i); if (element.method == 'post') { element.onsubmit = event => _submit(event, element); } }