Hi.
I need help with a HTML form, a Google Spreadsheet (credit for that) and a PHP confirmation page. The form sends data to the sheet and after ‘submit’ ([credit fot that
“`
<form name=”submit-to-google-sheet” action=”conf.php” method=”post”>
<input name=”email” type=”email” placeholder=”Email” required><br>
<input name=”name” type=”text” placeholder=”name”><br>
<input name=”apple” type=”checkbox” value=”Yes”> Manzana<br>
<input name=”orange” type=”checkbox” value=”Yes”> Naranja<br>
<input name=”banana” type=”checkbox” value=”Yes”> Banana<br>
<button type=”submit”>Enviar</button>
<p id=”response_message”></p>
</form>
This is the script that proves sending data to the sheet correctly. It also triggers the confirmation page, though its spaces left to provided data come blank:
“`
const scriptURL = ‘https://script.google.com/macros/s/AKfycbxJ9yXSrqqJCy82PV2eaIuNdfoLRWiayrBG1MT96n_av991Fuk/exec’
const form = document.forms[‘submit-to-google-sheet’]
form.addEventListener(‘submit’, e => {
e.preventDefault()
fetch(scriptURL, {
method: ‘POST’,
body: new FormData(form)
})
.then(response => {
console.log(‘Success!’, response );
window.location.href = “conf.php”;
}
)
.catch(error => console.error(‘Error!’, error.message))
})
However, if I turned `window.location.href = “conf.php”;`function () {window.location.href = “conf.php”;}
This is the relevant code of the confirmation page, by the way:
“`
<?php
setlocale(LC_TIME,”es_ES.utf-8″);
echo ‘Name: ‘ . $_POST [“name”] . ‘<br>’;
echo ‘E-mail: ‘ . $_POST [“email”] . ‘<br><br>’;
echo ‘You chose:’ . ‘<br>’;
echo ‘Apple: ‘ . $_POST [“apple”] . ‘<br>’;
echo ‘Orange: ‘ . $_POST [“orange”] . ‘<br>’;
echo ‘Banana: ‘ . $_POST [“banana”] . ‘<br>’;
echo strftime(“Submition date: %A %e de %B de %Y a %H:%M”) . ‘<br>’;
?>
Where’s my mistake? Thanks very mucn in advance.