I solved this with chatGPT. It made me a bit of javascript so the token could go into the http-request-header:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample Forms</title>
</head>
<body>
<h1>Sample Form 1</h1>
<form id="sampleForm1">
<label for="input1">Input 1:</label>
<input type="text" id="input1" name="input1" required><br><br>
<label for="input2">Input 2:</label>
<input type="text" id="input2" name="input2" required><br><br>
<button type="submit">Submit</button>
</form>
<h1>Sample Form 2</h1>
<form id="sampleForm2">
<label for="input3">Input 3:</label>
<input type="text" id="input3" name="input3" required><br><br>
<label for="input4">Input 4:</label>
<input type="text" id="input4" name="input4" required><br><br>
<button type="submit">Submit</button>
</form>
<script>
function handleFormSubmit(event, formId, nextPage) {
event.preventDefault();
const token = "your_auth_token_here";
const url = 'https://example.com/api/endpoint';
const formData = new FormData(document.getElementById(formId));
const postData = {};
formData.forEach((value, key) => {
postData[key] = value;
});
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify(postData)
};
fetch(url, options)
.then(response => {
if (response.status === 202) {
window.location.href = nextPage;
} else {
throw new Error('Network response was not ok');
}
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
}
document.getElementById('sampleForm1').addEventListener('submit', function(event) {
handleFormSubmit(event, 'sampleForm1', 'nextstep.html');
});
document.getElementById('sampleForm2').addEventListener('submit', function(event) {
handleFormSubmit(event, 'sampleForm2', 'nextstep.html');
});
</script>
</body>
</html>