Ajax $_get search terms lost after user clicks on result - php

Ive got a member search form that searches users on my site. The form method is get.
The results are displayed using Ajax on the same page. The page is not reloaded.
If a user clicks on a search result, then the appropriate page is opened in the same tab.
The problem comes when a user clicks back. Because the search result has opened in the same tab, clicking back returns you to the page with the search form, but all search results are lost. The user therefore has to start the search again.
The only solution i can think of is to not use ajax and post the search terms to the url. But thats not ideal.
Anyone got any better solutions - somehow storing the get variable so that ajax can pick it up again?

I think you used 'history.back()' for back button. You should use get or post to pass inputed variable of user to form search.

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.

PHP - Browser BACK button crashes the website

I am a newbie to programming. I have a PHP website which works as follows
Index Page - Search Results - Show a Product
The site user enters search critera on Index Page and the page is POSTed to Search Results page. From there, the site user clicks on a Product href that takes him to the Product Details. This is working fine till here.
The problem occurs when the user click the browser BACK button. The Search Result page comes up totally crashed and the user has to press F5/Browser Refresh to re-submit it. Any idea/technqiue that I can use to avoid this crash?
When a browser goes back to a page that comes from POSTing some data, the browser often times needs to re-POST the data in order to get the same page back. Since that can sometimes be bad (e.g. re-POSTing an order form), many browsers require the user to force a refresh with a warning.
You can generally use a GET instead of a POST form to avoid this.
An idea would be using GET for the method of your search form instead of POST (that apparently you are using). That way, even if going back in browser history, your server could re-supply its search results.
You would need the following:
change method="post" to method="get" in your search form
change every $_POST relating to the search form data to $_GET in your search form processing php file.
Of course, it could not work for your specific usecase. That's just an idea.

Display previous page results when we click back button in browsers

I have an application in PHP which is a search form.If i make a search in the search box and i submit the form then a list of products will get displayed then if i click any product it goes to the product page,now what is my issue is when i click the back option in the browser an alert for re-submission is getting still i go previous page search results are not shown
it is redirect to home page not to the search form also.
Since i have list of variables i am using POST method instead of GET method.But if i use GET method there is no issue but i want to know whether the same can be in POST method also.
Use GET. There's a lot of debate about what qualifies for each of the HTTP verbs, but generally speaking this fits squarely in the GET world. The POST warning by the browser is unwarranted: the first sign that you shouldn't be using it for this particular operation (search).

is there any way of going back to searched results page from detail page while preserving the records searched?

i have a search form page, which takes me to reslutant page and show me so me some records acc to search criteria. And by clicking on any of the record it takes me to its details page.
now there i had placed a back button on which i had used js script history.go(-1) to go back to the resultant page while showing the same results i had searched.
but instead it 1st show "CONFORM FORM RESUBMISSION" and after i press F5 then it show me the particular records.
Sounds like your search results page is a POST page. By default those are not cached by the browser, which is why you get that "form resubmit" stuff - the POST has to be reperformed and the page regenerated. Changing it to a GET will eliminate that.
Send you're search form data using GET , then it whont ask you to confirm form resubmission .

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