Hi there mauroian, glad it helped!
About the redirecting part: How do you decide whether the user is being sent to the success/error page? Is it based on whether the form was sent successfully to the spreadsheet, by one of the form's fields or by another criterion?
And try to replace it with (You can pick either one of the options with comments, no need for both of them):
.then((response)=>{console.log('Success!',response);// similar behavior as an HTTP redirectwindow.location.replace("https://dev.to/");// similar behavior as clicking on a linkwindow.location.href="https://dev.to/";});
Same goes for the error part, it should do the trick.
By the way, I think this might be important: in the original code, which was working, when I successfully submitted data to the spreadsheet, my HTML page did not change at all. It continued to show the input fields and submit button.
Basically, the line:
.then(response => console.log('Success!', response))
did nothing, as no 'Success!' message was shown in my page.
So, the issue could be in how/what the google script sends as response, or in the original code in index.html itself.
I am stuck at the moment... would be so happy if this worked!
It wasn't meant to do anything else besides sending to the spreadsheet.
In the following line:
form.addEventListener('submit',e=>{.............}
Everything between the { .... } will happen after the form is being submitted and you can modify it as much as you want, anything that happens there is up to your limits and not really relevant to this article or this mechanism :)
This whole article was only about the "sending-to-spreadsheet" part and nothing else, this is why nothing is happening other than that.
It already feels more of a tech support session than an easy js fix so just feel free to ping me wherever you'd like through one of the contact channels in my profile. The redirecting part is pure JS and can be found online but I'll try to help you out.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi there mauroian, glad it helped!
About the redirecting part: How do you decide whether the user is being sent to the success/error page? Is it based on whether the form was sent successfully to the spreadsheet, by one of the form's fields or by another criterion?
All I need is that the form was sent successfully to the spreadsheet. In which case, I'd like the user to be redirected to a success page :)
Try to find this line on the current code:
And try to replace it with (You can pick either one of the options with comments, no need for both of them):
Same goes for the error part, it should do the trick.
Done that. Now nothing gets submitted to the spreadsheet (and no redirect or anything else happens).
By the way, I think this might be important: in the original code, which was working, when I successfully submitted data to the spreadsheet, my HTML page did not change at all. It continued to show the input fields and submit button.
Basically, the line:
.then(response => console.log('Success!', response))
did nothing, as no 'Success!' message was shown in my page.
So, the issue could be in how/what the google script sends as response, or in the original code in index.html itself.
I am stuck at the moment... would be so happy if this worked!
It wasn't meant to do anything else besides sending to the spreadsheet.
In the following line:
Everything between the { .... } will happen after the form is being submitted and you can modify it as much as you want, anything that happens there is up to your limits and not really relevant to this article or this mechanism :)
This whole article was only about the "sending-to-spreadsheet" part and nothing else, this is why nothing is happening other than that.
It already feels more of a tech support session than an easy js fix so just feel free to ping me wherever you'd like through one of the contact channels in my profile. The redirecting part is pure JS and can be found online but I'll try to help you out.