/    Sign up×
Community /Pin to ProfileBookmark

HTML form to Google spreadsheet with confirmation page. PHP code conflict

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](https://github.com/jamiewilson/form-to-google-sheets)) it returns the confirmation page that reproduces the information the user gave. Both steps work fine separately but I can’t make them work together. So this is the HTML code for the form:

“`
<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”;` into `function () {window.location.href = “conf.php”;}` confirmation page is correct with expected information but the form does not populate the spreadsheet. I can set this function in multiple lines and the effect is the same.

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.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @LaCaradeculito spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...