1

My situation: On the html page i click the button to submit my form . And after process of php , send back the result to html page and bring out . But when i refresh my page , and pop-up the window and ask me whether or not send the form data again . But now i don't want to let this window appear , i google and get some solutions , redirect or the others , but my problem won't be solved. How can i do for my problem .

Notice: I will use the data of the php process and send back , so i can use the redirect method . Thanks all .

user2677996
  • 11
  • 1
  • 3

1 Answers1

1

The simplest solution is to split your page into 2 parts.

The first part presents the page to the browser but instead of submitting back to the same page you submit to another page. Once that page has done what is required with the data from the page you redirect to the original page.

So page xxx.php collects any data required before presenting the page to the browser and has an <form action="xxx_upd.php"....>

And page xxx_upd.php just reads $_POST or $_GET and processes the input, once complete it does a header( 'Locaction: xxx.php' ); to cause the first page to reload but as it has been reset to initial state by this process it will not cause the message when you refresh the page and will not try to re-run the processing which is now done by xxx_upd.php

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • Just for others who might want to research this technique further, this is generally known as the PRG pattern, or Post, Redirect, Get, as the form does a **post**, the server responds with a **redirect**, and the browser receives the redirect and performs a **get**. k4RIa's answer of using AJAX submit is equally valid, despite omitting implementation details which are readily available in other questions focused on that topic... – AaronLS Aug 13 '13 at 22:25