How can i prevent repeat submit when i refresh web page? - php

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 .

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

Related

How to go back without asking to confirm resubmission of the form

I have a web page that loads all the data from a mysql database called datalist.php
From this page I can edit record by record with a button that redirects you to an editdata.php page adapted to the fid of the record.
Once edited as they want to see the changes, I don't redirect them to the main one letting them see the changes and simply clicking back or with a button they return to the datalist.php without any problem.
The button is this
echo "<p id='parrafo'><a style='padding:1px 20px'class='button rounded-0 primary-bg text-white w-0 btn_1 boxed-btn' href='javascript:history.back() '><--</a></p>";
PROBLEM
I added a search engine where the displayed data can be filtered.
When they use the search engine from datalist.php, I direct them to a page called search engine.php where, through a post method, I store what they are looking for in a variable and the data that users want appears.
But when they edit a filtered record, it is edited without problems, but when they go back, they return to the search engine.php and the message appears:
"Confirm form resubmission In order to display correctly, this web page needs the data you entered earlier. You can submit that data again, but that will cause the page to repeat all previous actions. Press Reload to submit the data and display the page.
Hit the page refresh button to resubmit the data needed to load the page."
Of course, if they update, they come back when the filtered data comes out.
Isn't there any way to store the variable used in the search so that when I go back I don't get this error or any solution??
simple! when user will submit form for that variable instead of making post request
option1: just use get request __url__?variable=... but this will not remember the variable when you go back
option2: store the variable in the cookie and just go to next page (eg. window.location.href = '...';). and in next page access the cookie from php.
If you are wanting to show the form to the user as a confirmation, but without the possibility of another post, then remove the form element and the button. Display all other boxes as they are (with the values populated from the POST array).
And display another message telling them that it has been successful.
You are using PHP, you can achieve this easily with it. If you are unsure, then post a short version of your code in a separate question.

GET rid of a page from browser history

I have a page for example, say first.html. it has a form with action set to, say xyz.php.
This php file ,after processing , sends a header () with location . Now browser fetches the page.
Now when I click back button ,first.html shows.
Is there a way to get rid of that first.html page and show other page from history?
When there's a redirect if you want to replace the page that triggered the redirect you can use window.location.replace(newUrl).
Here's the documentation for replace

How to remove Confirm Form Resubmission when redirect using a button with a value to another page

Good day, as the title says, how can I do that? What I'm trying to do is that on page 1, I looped all data with each having a button that has value of their specific id, then that button redirects to a common page 2, then I use that id on page 2 to display their whole data, but the problem is that when I refresh, the dialog appears.
I tried using session, but the problem is that when multiple tabs are accessing it.
I haven't really tried PRG, but on my understanding, it is used to send changes to the server using another page, then redirect to the previous page, preventing the dialog when refreshing. I thought of using it, but I don't know how to send the fetched data from page 1.5 to page 2
I'd be really grateful for a solution to this, or if someone can link me to similar problems. Maybe this is a duplicate question, but I just can't find the term for my problem. Cheers!!
If you control both pages, change the redirect mechanism on page 1 to GET by simply redirecting to a URL with a parameter appended to the address: target.php?id=42.
If you control only page 2, you may convert a POST request with an id to a GET request:
if (isset($_POST['id']))
{
header('Location: target.php?id=' . $_POST['id']);
exit;
}
More on GET vs POST here, as well as a couple of other answers.

document expired after pressing back button

I have a page called a.php . It has a form and submit data via POST to same file (a.php) . Page loads with no error. Then I click any link (b.php or b.html) on that page . it directs to any page as usual. Then when I click back button from b.php or b.html it does not show previous page.
Any help to solve this matter ?
Thanks
About Method
The $_POST Method used for SUBMITTING FORMS something Create or Modify it is a secure method.In other words POST is sending data to server from browser
FOR EXAMPLE
Creating Articles
Editing Articles
File Uploading
In your case you are getting values POST is not for getting values Use $_GET method for this
Why Document Expires ?
I taken this Image from wikipedia.
Why Browser Do this?
It is because it prevent from duplicate submission.
For Example : On any shopping site there are payment options user buy a product and pay for it , now if he/she(user) refresh page again the payment done two times .
according to your question, page a.php is submitting data (post) to the page itself, so if you go to other page and then want to back again to page a.php (by clicking the back button on browser) it causes document expired because when you click it you are not submitting any data (post) to page a.php.

Redirecting to multiple page after form submission

i have a form. In the action field i have given a page location where the control should redirect after submit. But i want to redirect to multiple page after submit. And the next page should open in new tab. I know about target_blank option. I just want to know how to redirect to multiple pages after submit. Thank you.
You can use this script in your submit form page
<script>
window.open('link','_blank');
</script>
What do you mean by redirect?
Do you want the submit button to send form data to two pages?
If yes this can be achieved by using session variables and opening a new window on the redirected page.
1) save the form data in session variables.
2) load the 1st page
3) use php script or you can use window.open("url") in the 1st page to redirect to a new page on a new tab.

Categories