Html form submission | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 12

Html form submission

after submitting a form and the user is on another page, if the user goes back to previous page how can I prevent the user from going back to the form

20th Jun 2020, 1:38 PM
Daya Bianca
Daya Bianca - avatar
22 Answers
+ 11
I understand your question Daya Bianca, you can do that by making the former page url expire, which is used by mist banks website, you can also use javascript to delete former page history. you can replece history, instead of using window.location = url; to redirect, try: window.location.replace(url); after using replace() the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it, bcoz after loading the page the history is replace with another url. replaceState may also help. This links may help also: https://stackoverflow.com/questions/37511043/how-to-stop-re-submitting-a-form-after-clicking-back-button https://www.the-art-of-web.com/javascript/doublesubmit/ https://www.w3schools.com/js/js_cookies.asp
20th Jun 2020, 9:37 PM
Awojobi Godfrey
Awojobi Godfrey - avatar
+ 5
The submit of your form i.e. as follows: function withoutBack() { location.replace('http://www.myNewUri'); }
20th Jun 2020, 4:30 PM
JaScript
JaScript - avatar
+ 5
Web is not something I am very knowledgable about. If you only use one page with divisions getting updated, back will take them off your site so no issue.
20th Jun 2020, 5:53 PM
John Wells
John Wells - avatar
+ 5
A simple php session will do. You don't need to learn much. Start a session at the top of your page before any html using session_start(); and store data with $_SESSION Any other page that has session started will be able to access that data https://www.w3schools.com/php/php_sessions.asp
20th Jun 2020, 10:15 PM
HNNX 🐿
HNNX 🐿 - avatar
+ 5
Abdulazeez You can create links as usually to other websites. This do not work here on SL Playground. So you have to use another web server. Next time please ask in you own thread.
17th Apr 2023, 4:48 PM
JaScript
JaScript - avatar
+ 4
The location.replace(URL_2); method replace browser history‘s last page URL_1 = „where is/was your form with questions“ with the web page URL_2. An example: <input id="myIn"> <button type="button" onclick="validateIn(this)">submit</button> <script> function validateIn() { var x = document.getElementById("myIn").value; if (x == "") { alert("This must be filled out"); return false; } location.replace('https://www.sololearn.com/'); } </script>
20th Jun 2020, 8:39 PM
JaScript
JaScript - avatar
+ 4
Ja Play, the code can't be placed here, I am dealing with more than 1 web page, which sololearn code playgroubd does not support
21st Jun 2020, 1:54 PM
Daya Bianca
Daya Bianca - avatar
+ 3
Seniru how can I use cookies
20th Jun 2020, 5:42 PM
Daya Bianca
Daya Bianca - avatar
+ 3
I had a question like that
22nd Jun 2020, 1:26 PM
Jeannot Richecarde
Jeannot Richecarde - avatar
+ 2
Instead the user should go to another page
20th Jun 2020, 1:41 PM
Daya Bianca
Daya Bianca - avatar
+ 2
Which I will redirect the user myself
20th Jun 2020, 1:41 PM
Daya Bianca
Daya Bianca - avatar
+ 2
Ja Play pls how does the location.replace works
20th Jun 2020, 5:43 PM
Daya Bianca
Daya Bianca - avatar
+ 2
John Wells, Oma Falk, Lord Krishna please I will like an explanation to this
20th Jun 2020, 5:45 PM
Daya Bianca
Daya Bianca - avatar
+ 2
I hope you are okay with my answer Daya Bianca
21st Jun 2020, 9:51 PM
Awojobi Godfrey
Awojobi Godfrey - avatar
+ 2
looking for team members to start a project with..
23rd Jun 2020, 10:39 PM
kel Mar
kel Mar - avatar
+ 2
kel Mar am interested
24th Jun 2020, 1:18 PM
Daya Bianca
Daya Bianca - avatar
+ 2
kel Mar I'm interested
24th Jun 2020, 5:36 PM
Jeannot Richecarde
Jeannot Richecarde - avatar
+ 1
Not sure, but maybe cookies is the answer
20th Jun 2020, 2:06 PM
Seniru
Seniru - avatar
+ 1
Thanks Awojobi Godfrey, understood now
21st Jun 2020, 9:54 PM
Daya Bianca
Daya Bianca - avatar
+ 1
How do you create content of the page you want users to navigate to for multipage websites?? Pls,I need help... for local files/webpage
17th Apr 2023, 4:42 PM
Abdulazeez
Abdulazeez - avatar