In my solution, first of all, detect each form input is received and saved by the database properly. If it is a successful attempt, then execute the success function to refresh… Show
In my solution, first of all, detect each form input is received and saved by the database properly. If it is a successful attempt, then execute the success function to refresh the page without resubmitting the form by printing a script in PHP as you can inspect below.In my solution, first of all, detect each form input is received and saved by the database properly. If it is a successful attempt, then execute the success function to refresh the page without resubmitting the form by printing a script in PHP as you can inspect below.
177 votes 23 answers Get the solution ↓↓↓I have a simple form that submits text to my SQL table. The problem is that after the user submits the text, they can refresh the page and the data gets submitted again without filling the form again. I could redirect the user to another page after the text is submitted, but I want users to stay on the same page. I remember reading something about giving each user a unique session id and comparing it with another value which solved the problem I am having but I forgot where it is. 2022-02-17 594 votes AnswerSolution:I would also like to point out that you can use a javascript approach,
Proof of concept here: https://dtbaker.net/files/prevent-post-resubmit.php (Link no longer works) I would still recommend a Post/Redirect/Get approach, but this is a novel JS solution. Undefined answered 2022-02-17 Link to answer 327 votes AnswerSolution:Use the Post/Redirect/Get pattern. http://en.wikipedia.org/wiki/Post/Redirect/Get With my website, I will store a message in a cookie or session, redirect after the post, read the cookie/session, and then clear the value of that session or cookie variable. Undefined answered 2022-02-17 Link to answer 409 votes AnswerSolution:You can prevent form resubmission via a session variable. First you have to set
After that check
Make sure you start the session on every file you are using it with Undefined answered 2022-02-17 Link to answer 750 votes AnswerSolution:This method works for me well, and I think this is the simplest one to do this job. The general idea is to redirect the user to some other pages after the form submission, which would stop the form resubmission on page refresh. Still, if you need to hold the user on the same page after the form is submitted, you can do it in multiple ways, but here I am describing the JavaScript method. JavaScript MethodThis method is quite easy and blocks the pop up asking for form resubmission on refresh once the form is submitted. Just place this line of JavaScript code at the footer of your file and see the "magic".
Undefined answered 2022-02-17 Link to answer 792 votes AnswerSolution:I use this javascript line to block the pop up asking for form resubmission on refresh once the form is submitted.
Just place this line at the footer of your file and see the magic Undefined answered 2022-02-17 Link to answer 63 votes AnswerSolution:You should really use a Post Redirect Get pattern for handling this but if you've somehow ended up in a position where PRG isn't viable (e.g. the form itself is in an include, preventing redirects) you can hash some of the request parameters to make a string based on the content and then check that you haven't sent it already.
Undefined answered 2022-02-17 Link to answer 173 votes AnswerSolution:When the form is processed, you redirect to another page:
you can also redirect to the same page. if you are doing something like comments and you want the user to stay on the same page, you can use Ajax to handle the form submission Undefined answered 2022-02-17 Link to answer 928 votes AnswerSolution:I found next workaround. You may escape the redirection after processing So you have the HTML form:
When you process this form on your server you instead of redirecting user to
After processing
The
The result is: as you can see the form data is
UPD As another solution I ask feature
request the Mozilla FireFox team to allow users to setup In short. When server process form
The browser in turn when see the
I think this would be excelent if implemented, would not? Undefined answered 2022-02-17 Link to answer 84 votes AnswerSolution:
Undefined answered 2022-02-17 Link to answer 790 votes AnswerSolution:A pretty surefire way is to implement a unique ID into the post and cache it in the
Then in your code do this:
Undefined answered 2022-02-17 Link to answer 129 votes AnswerSolution:Just redirect it to the same page after making the use of form data, and it works. I have tried it.
Undefined answered 2022-02-17 Link to answer 292 votes AnswerSolution:A refined version of Moob's post. Create a hash of the POST, save it as a session cookie, and compare hashes every session.
Undefined answered 2022-02-17 Link to answer 790 votes AnswerSolution:Basically, you need to redirect out of that page but it still can make a problem while your internet slow (Redirect header from serverside) Example of basic scenario : Click on submit button twiceWay to solve
Undefined answered 2022-02-17 Link to answer 979 votes AnswerSolution:How to prevent php form resubmission without redirect. If you are using $_SESSION (after session_start) and a $_POST form, you can do something like this:
In your html form put this:
So, every time when the form is submitted, a new act is generated, stored in session and compared with the post act. Ps: if you are using an Get form, you can easily change all POST with GET and it works too. Undefined answered 2022-02-17 Link to answer 73 votes AnswerSolution:After inserting it to database, call unset() method to clear the data. unset($_POST); To prevent refresh data insertion, do a page redirection to same page or different page after record insert. header('Location:'.$_SERVER['PHP_SELF']); Undefined answered 2022-02-17 Link to answer 187 votes AnswerSolution:The $_POST['submit'] variable would not exist on initial loading of page, and curl can be run only if below condition is true.
Undefined answered 2022-02-17 Link to answer 811 votes AnswerSolution:Using the Post/Redirect/Get pattern from Keverw answer is a good idea. However, you are not able to stay on your page (and I think this was what you were asking for?) In addition, it may sometimes fail:
Another option would be to store in a session if text should be written to your SQL database like this:
Undefined answered 2022-02-17 Link to answer 988 votes AnswerSolution:As others have said, it is not possible to out of using post/redirect/get. But at the same time it is quite easy to do what you want to do server side. In your POST page you simply validate the user input but do not act on it, instead you copy it into a SESSION array. You then redirect back to the main submission page again. Your main submission page starts by checking to see if the SESSION array that you are using exists, and if so copy it into a local array and unset it. From there you can act on it. This way you only do all your main work once, achieving what you want to do. Undefined answered 2022-02-17 Link to answer 670 votes AnswerSolution:I searched for solution to prevent resubmission in a huge project afterwards. The code highly works with $_GET and $_POST and I can't change the form elements behaviour without the risk of unforeseen bugs. So, here is my code:
It only works to avoid the resubmit of $_POST, not $_GET. But this is the behaviour I need. The resubmit issue doesn't work with file uploads! Undefined answered 2022-02-17 Link to answer 568 votes AnswerSolution:What Works For Me is :
And in your Form
Undefined answered 2022-02-17 Link to answer 880 votes AnswerSolution:This
Undefined answered 2022-02-17 Link to answer 632 votes AnswerSolution:
$everything_fine is the boolean result of form-validation. If the form is not validating then it shall be usually displayed again with a hint what to correct, so that the user can send it again. Therefore the $_SESSION['uniq'] is created again too if a corrected form is desired Undefined answered 2022-02-17 Link to answer 264 votes AnswerSolution:Why not just use the Undefined answered 2022-02-17 Link to answer People are also looking for solutions of the problem: call to
undefined function illuminate\encryption\openssl_cipher_iv_length() ShareDidn't find the answer?Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free. Similar questionsFind the answer in similar questions on our website. Write quick answerDo you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger. About the technologies asked in this questionPHPPHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most
hosting providers, it is one of the most popular tools for creating dynamic websites. The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license. JavaScriptJavaScript is a multi-paradigm language that supports event-driven, functional, and mandatory (including
object-oriented and prototype-based) programming types. Originally JavaScript was only used on the client side. JavaScript is now still used as a server-side programming language. To summarize, we can say that JavaScript is the language of the Internet. JQueryJQuery is arguably the most popular JavaScript library with so many features for modern development. JQuery is a fast
and concise JavaScript library created by John Resig in 2006. It is a cross-platform JavaScript library designed to simplify client-side HTML scripting. Over 19 million websites are currently using jQuery! Companies like WordPress, Facebook, Google, IBM and many more rely on jQuery to provide a kind of web browsing experience. HTMLHTML (English "hyper text markup language" - hypertext
markup language) is a special markup language that is used to create sites on the Internet. Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone. Welcome to programmierfrage.comprogrammierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration. Get answers to specific questionsAsk about the real problem you are facing. Describe in detail what you are doing and what you want to achieve. Help Others Solve Their IssuesOur goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge. How do I stop confirmation resubmission in PHP?If you are using form in header with this PHP code then you can prevent Confirm Form Resubmission error. That code usually is; header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); Now to fix it, simply delete ('no-store') from the header.
How do you prevent a form from submitting when the page is refreshed?Use the preventDefault() method on the event object to prevent a page refresh on form submit in React, e.g. event. preventDefault() . The preventDefault method prevents the browser from issuing the default action which in the case of a form submission is to refresh the page.
How do I turn off confirmed resubmission?How to Disable Confirm Form Resubmission Popup. First, right-click the Google Chrome shortcut icon and choose the Properties option.. You will be able to open a dialog box and get a field named Target.. Now add this text to the target's end, "deactivate-prompt-on-repost" (no quotes).. For me, the target is:. How do I stop resending data on Refresh in laravel?After pressing F5 the input is still displayed. Last updated 3 months ago. If your on the response to the post and you refresh it is going to resubmit, normal behavior. Redirect away to stop a resubmit.
|