-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Beginner trying to redirect users to an HTML page instead of Appscript JSON result #13
Comments
Put it in your website's source code |
@shadichy thank you for the reply i am in this moment fighting with it I dont see why it doesnt work I ll make an other html file with form including the appscript link for POST method and add the JS code at the end en of the body with <Script> JS </script> |
@shadichy @levinunnink @meandavejustice I just tried it and :
For information, i am using bootstrap, it may change something, i don't know ! Here is the code source joined |
This one doesn't work ` <script>window.addEventListener("load", function() { const form = document.getElementById('myform'); form.addEventListener("submit", function(e) { e.preventDefault(); const data = new FormData(form); const action = e.target.action; fetch(action, { method: 'POST', body: data, }) .then(() => { alert("Success!"); }) }); }); </script>` Nor this one ` <script>window.addEventListener("load", function() { const form = document.getElementById('myform'); form.addEventListener("submit", function(e) { e.preventDefault(); const data = new FormData(form); const action = e.target.action; fetch(action, { method: 'POST', body: data, }) .then(() => { window.location.replace("http://www.w3schools.com"); }) }); }); </script>` |
@elmoumenyassine First, assign an id to your form ( window.addEventListener("DOMContentLoaded", function() { // 'window.onload = function...' also works
const yourForm = document.getElementById("yourFormID");
yourForm.addEventListener("submit", function(e) { // 'yourForm.onsubmit = function...` also works too
e.preventDefault();
const data = new FormData(yourForm);
const action = e.target.action;
fetch(action, {
method: 'POST',
body: data,
}).then((response) => {
response.json();
}).then((data) => {
if (data.result == "success") {
// finished, you can do whatever you want here
alert("Success!")
}
})
})
}); to your js source or HTML source (inside |
@levinunnink I think you should close this now |
I am also looking for the solution. Above responses are not working. |
Detail please |
@shadichy First of all, thanks for your time and comments. The code succeeds (ie., I get the Success alert) but only 1 of the two values I need are copied to the sheet. Here's my code:
In my spreadsheet I have three columns: date (automatically completed by the App); URL (the value is dynamically identified using the function above); and Helpful? (either yes or no depending on which input the user clicks on). The Helpful? input isn't being posted. Any thoughts? |
Modify your google appscript, the problem is there, not this |
I have the same problem and none of the possible solutions is working for me, everytime the contact form is submited it redirects to script.googleusercontent.com/ |
To chime in on what @asd1495 said above, I can definitely redirect to another page. The issue is that it doesn't really redirect; it displays my page, but the URL still says script.googleusercontent.com/... . And this remains even as you click other links (which itself seems like a security problem). If you hit refresh, it resubmits the original form. I'm a little confused about the general lack of solutions to this problem; I've been hunting for a while and every option seems to not work. How is anyone even using this without being able to send the user on to another page, rather than just showing them a JSON response? |
redirect it to a blank iframe |
Thanks. I'm not sure I understand how I'd do that. Right now, I'm using this code after inserting the spreadsheet rows:
And the contents of my-response-page (in the Google Apps Script project) is simply:
It does correctly redirect to that resulting page, but inside a frame, and nothing I do inside that frame seems to be able to break out or change the top URL. For example, I put this script in the head of the page:
But no change. The frame page source is as follows:
Could this be related? https://developers.google.com/apps-script/reference/html/x-frame-options-mode |
hmm |
i've managed to deal with that before, just, I might have to find it =)) |
Did anyone find solution for the redirect to custom url instead of apps script return? |
JS fetch |
https://codepen.io/levinunnink-the-bashful/pen/YzxPyoG?editors=1010 Using this method: #13 (comment) Anyone have a solution? I would like to redirect to a success.html file i created on success POST, instead of the json page https://script.googleusercontent.com/macros/echo |
Don't make any changes in apps script, but I modified in my html code like this and after alert it redirects to home page $('form').each(function() { this.reset() });
|
Hello Author,
I am a beginner and i didn't understand the note saying :
I dont want the user to have an "https://script.googleusercontent.com/macros/echo?user_content_key=....etc"
and a JSON response like this :
The JS in codepen is the following. I don't really understand were to put it. Can you help me please ?
Before all i have to say that i was more a lowcoder (with appsheet and Excel VBA)
Thank you by advance
window.addEventListener("load", function() { const form = document.getElementById('my-form'); form.addEventListener("submit", function(e) { e.preventDefault(); const data = new FormData(form); const action = e.target.action; fetch(action, { method: 'POST', body: data, }) .then(() => { alert("Success!"); }) }); });
(i created a Github account just because of this. A great opportunity :) )
El Moumen Y.
@levinunnink
@meandavejustice
@shadichy
The text was updated successfully, but these errors were encountered: