How to handle post variable data while clicking on back buton - php

I am trying to make some naviations like page 1 having some data which need to post on page 2. with the help of form & hidden elements i am sending that data to page 2 & accepting that using $_POST method.again having some data which need to send page 3 using same post method method & hidden input element. On page page 4 i am accepting data using same method like $_POST.I getting data over there as i want.
But I am trying to click back button from page 4 to page 3 then the page which having some data posted from page 2. that data is missing from there and getting error like "Confirm Form Resubmission". I have tried the same thing with $_SESSION but its not working here.
Can anyone tell me how to resolve this issue.Kindly see this image attachment

That isn't an error page you're seeing. The Confirm Form Resubmission page is asking if you want to post the data again. So it is asking you if you want to reload Page 3, with the data sent from Page 2.
This is standard web browser practice, and is replicated across all browsers.
Possibly a stupid question, but have you actually tried reloading this page, and accepting the resubmission of data?

Use session mechanism to store intermediate data on server side between steps. To avoid form resubmit issue, redirect after each POST to the next step using header() function. So, each page will be loaded using GET method and easily be "Back" button compatible.

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.

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.

Submitting a form on a live webpage with PHP

I'm trying to find a way for PHP to press the "submit" button on a PHP form on a live webpage.
I need to do this as I am unsure as towards what data is send through this form, as it is a post form and the API is closed source.
Is there anyway to send a jQuery like click command to a live webpage through PHP at all?
Nothing needs to be retrieved from this form, only needs to have pressed the button correctly.
EDIT
More context:
Yes, the site is 3rd party (this is why I can't simply look up something on any API documentation), the program is downloading a gallery of images through the in-site gallery archiver. Previously the URL for this gallery's archive was stored on a simple popup window page's source. Now however you must confirm it first the page reloads (after a form submits through POST) onto the same page (archiver.php) and the download starts. This reloaded page contains the URL of the file. Nothing is submitted beyond the users confirmation to the download manually, perhaps something in the back end is sent upon this, I don't know.
EDIT 2
I've fixed this by figuring out what the form submits.
I think it is not possible to click a button on another page with php or jquery.
But you can analyse the form and find out the destination URL and send a own request. If it is GET it should look like this: myhomepage.com?id=1&name=foo&password=hello123
you have to use jQuery or javaScript For pressing submit button on live page dynamically. PHP is server side script and from is client side so its not possible. but if you want to read data from live webpage than you have to use cURL or file_get content

HTML-form does not post back anymore after post with content-disposition

I don't know if it is a feature by design or something that I do wrong.
On a webpage I have a HTML-form which after a post back generates a PDF-document. This document is provided via as content-disposition. The idea was that the current page remains operation and the user can continue with its work.
But after a post back the PDF-document is provided as download, the current page stays in the browser. But the form does not post back another time.
In the form some input fields have to be filled in to be inserted in the document.
Technical order:
1) HTML form -> post
2) PHP request -> handle post and deliver PDF-document as download
3) page is browser remains the same, but does not post back anymore
Is this behavior by design or do I do something wrong in the PHP script?
Well, the problem was something of my own.
On the page a script was loaded which disabled all submit buttons after they where pressed to prevent multiple post backs.
So no weird feature of bug, but a own made problem.

How to display results so back button does not ask to reload POST variables

I have a form that uses XML to get results. From those results users can click to a detail page. My problem is when a user clicks back to the results page, they are asked if they want to submit the form again. How do I create this so back button just displays the results, like on aa.com, ebay, autotrader, etc.
Thanks!
When you submit your page move the $_POST variables into the $_SESSION array and then header redirect the user to the results page.
You should redirect to another page to using redirect() method of codeigniter. This will prevent the browser asking a confirmation on form submission.
Is it just a search page that displays results? Why not use GET rather than POST in your form? Looking at search engines out there, they seem to use GET for their search interface. I can think of a few reasons to use GET rather than POST.
If the operation simply fetches results, semantically, the GET method is more appropriate. GET is used when you are fetching data. POST is more used when you are submitting a change to the application.
If you use GET, clicking on the back button won't give you a dialog asking whether you wish to resubmit the form.
Your users will have a URL directly to a search results page for a particular query that they can share.
Unfortunately CodeIgniter, by default, nukes the query string when processing a request. You can enable the query string in CodeIgniter by following this answer.

Categories