LMIV-SNACKAUTOMAT/form_test.html

59 lines
2.2 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Form Submit Test</title>
<meta charset="utf-8">
</head>
<body>
<h1>Form Submit Test</h1>
<h2>Test 1: GET Request zur Debug Session</h2>
<button onclick="testSession()">Test Session Status</button>
<div id="sessionResult"></div>
<h2>Test 2: Form Submit mit JavaScript</h2>
<form id="testForm">
<label>
<input type="checkbox" name="show_prices" value="1" id="show_prices"> Preise anzeigen
</label><br>
<label>
<input type="checkbox" name="show_stock" value="1" checked id="show_stock"> Bestand anzeigen
</label><br>
<button type="button" onclick="testFormSubmit()">JavaScript Test Submit</button>
</form>
<div id="formResult"></div>
<script>
async function testSession() {
try {
const response = await fetch('http://localhost:8001/debug/session');
const data = await response.json();
document.getElementById('sessionResult').innerHTML = '<pre>' + JSON.stringify(data, null, 2) + '</pre>';
} catch (error) {
document.getElementById('sessionResult').innerHTML = '<p style="color: red;">Error: ' + error.message + '</p>';
}
}
async function testFormSubmit() {
try {
const formData = new FormData();
if (document.getElementById('show_prices').checked) {
formData.append('show_prices', '1');
}
if (document.getElementById('show_stock').checked) {
formData.append('show_stock', '1');
}
const response = await fetch('http://localhost:8001/debug/tenant-test', {
method: 'POST',
body: formData
});
const data = await response.json();
document.getElementById('formResult').innerHTML = '<pre>' + JSON.stringify(data, null, 2) + '</pre>';
} catch (error) {
document.getElementById('formResult').innerHTML = '<p style="color: red;">Error: ' + error.message + '</p>';
}
}
</script>
</body>
</html>