i've a search bar from where users can search for videos..
after the search, the user goes on to click and watch a video(from the search result)..when the user hits the browser's back button it displays the following
To display this page, Firefox must
send information that will repeat any
action (such as a search or order
confirmation) that was performed
earlier.
instead of just showing the results..
i just want to display the results of search when the user hits back..is it something related to cache?
thankx..
Preferably, change your search form's method to get, or use the Post/Redirect/Get pattern.
That message is displayed because POST data needs to be resent to re-render the page.
If you don't want that, you can use GET instead of POST for your form method.
ie, you should use something like this :
<form action"yourpage.php" method="get">
...
</form>
instead of :
<form action"yourpage.php" method="post">
...
</form>
This way, the parameters used in the form will be sent in the URL, and not by POST, and users will be able to :
use back with no problem, independantly of the browser's cache
bookmark the result page (which is nice ^^ )
And I should add that, in theory :
POST has to be used when you want to create/modify data
and GET has to be used when you want to... well, get, data.
When searching for something via a search form, your users are not creating nor modifying data : they are asking for data -- so, your form should use the GET method.
To remove this problem, replace the existing top.location.reload() or parent.location.reload(); with top.location.href=top.location.href;.
No, it's not a cache issue. The problem is that you are using POST to submit the search form. There are a couple of solutions.
The better one is change the form to use GET. You can do that by setting its method attribute like
<form method="get" action="search.php">
The other, if you fear that the search query will get way too long you can save the search with some form of id and then redirect to a page that fetches this search id and shows the result. Redirecting can be done with
header('Location: show_search.php?id=' . $searchId);
Related
I am fairly new to using PHP so bear with me if this is a stupid question
I have a form that comprises a number of radio buttons, the action is set to redirect to the same page and the method is GET.
A click on a radio button gets data from the database. The data is used to redisplay the same page with changed content.
The page URL has PHP arguments in it like the example below
localhost/basesite/mypage.php?itemID=8&name=city&number=9
When I access the page and click on a radio button I get a page with “no arg” because the URL reads
localhost/basesite/mypage.php?number=6
Two of the arguments are missing and that the last one is incorrect.
With no change whatsoever to the code except using ”post’ instead of “get” the whole thing works flawlessly.
I have used
form action= "" method=“get”
form action= “#” method=“get”
and many other actions using $_SERVER["REQUEST_URI”], $_SERVER['QUERY_STRING'] etc and combinations thereof.
Those that worked with POST did not work with GET.
I do not need to use POST as data is not written only retrieved from the database so I have no worry about data being written more than once.
If I have to I will use POST but if the user refreshes or uses the back button then the usual warnings will be issued by the browser.
What am I missing?
you should you use $.get which is a jquery method.
First, you should share your full source code for better understanding your problem. And also you have to use post method to submit a radio button values to get some value from your database. Form data can be submitted using these two methods (get and post). Both are used for the same purpose, but stands apart under some specifications. As in GET method key values are passed in the Url while in POST, the information transfers in a hidden manner.
Sorry folks. It was a badly formed URL due to me not fully understanding how to set a hidden element.
I need to take form data from user input- i.e. radio buttons and use that to apply search filters to a database search.
However there are specific parameters which are giving me difficulty.
Specifically: The search filter options pane is a static fixture on the main page of the site. The query to be modified by the search filters is a separate php page which is called by an ajax function to display search results in the middle of the page without page refresh.
Is it even possible to submit variable values to another php page without going to that page and processing the php immediately? Or will the variables not be stored like that?
The code is too long but I'll give basic pseudocode:
Form action="Query Page to receive user input.php"
Some radio buttons:
20
15
10
Submit button--> Submits the radio button value to QueryPage.php but does not redirect
User clicks a category link (i.e. fitness) that calls the ajax function which displays the output of QueryPage.php. At this point QueryPage.php should perform the search with the specific user input filters that were selected earlier.
Is this possible?
Let me see if I understand correctly:
You're basically saying that your radio buttons will modify the search results, based on the what user selected?
If that's the case, I can think of 2 options:
1- When you make the ajax request for the search, first, grab the user input and send it to the QueryPage.php file with the search query. Do you have access to that function?
2- Post the user input using ajax (are you using jQuery or some other library for this?) to a UserInput.php file, where you'll store that data on the session, and then from QueryPage.php you just access the session and grab the values sent previously.
Does that answer your question? Sorry if it doens't, it's a bit hard to understand the problem.
You can use JQUERY and its events method. For example change,click,hover. In your case you want to use radio buttons, so you might wanna use the click event for that.
$("#radio").click(function () {
// SEND HTTP REQUEST
});
http://www.mkyong.com/jquery/how-to-select-a-radio-button-with-jquery/
Yes. You could just use .ajax(), or .post() or cURL. This will post your data to the specified page without redirecting.
Example using .post()
$.post("test.php", { name: "John", time: "2pm", fieldname: "your value" } );
Yes, Im having a little edit profile page, index.php?mode=profile. Lets take the username in the editprofile form as example. The username is already in the username-field. So i changed from "Peter" to "Tom" and press save.
The action is ?mode=profile&edit=true. So now when i have pressed save it has updated the column in the db from Peter to Tom. But this field keeps having the value "Peter" until if i do press refresh (or f5), then "Tom" will appear. Like it hasnt updated in the database anything, although it did but it still shows Peter until next refresh.. like it caches, but it shouldnt cache nothing?
Any help on this? Is it because its on the same "page" / file? what can i do
I think you fetch the data first, put it in the form and then update the database contents. You should update the database contents first when you submit the form. The fetch and creation of the form should be the next step.
Most likely you're rendering the page before doing any of the profile modifications. Make sure you're dealing with changes to the profile before you render it (i.e., all your database calls to update values should be before the SELECT statements to render the page).
HTTP provides two methods : POST and GET. With URL starting with ?param= you are actually using GET. "GET" should be used if and only if the form processing is idempotent query (ie the page content is NOT altered by the query).
If your form modifies data, you should use POST method.
What you can do is in each input field of your form just echo post values for respective fields.
For eg -
lets take an example of username field -
<input type="text" name="username" value='<?php echo $_POST['username']?>' />
By this way if you post any field then that value will be displayed and not from cache.
In my above example i haven't cleaned the post data, make sure that you use cleaned post data
in actual scenario.
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.
I want to do a search with pagination, but I don't know how to 'store' the data in the $_POST array, should I do it with sessions?
Rolensen
If you are doing a search, you are trying to GET data from the server, and not send data to it -- which means you probably should use GET, and not POST.
Also, it would allow your users to bookmark the result pages (or send those links by e-mail, IM, ...), which is always nice ; and, also, use the back/forward buttons of the browser without getting an alert box, which is nice too ^^
(Oh, and, BTW, it would help solve your problem ;-) )
Yes, you can use sessions or hidden fields and even better GET method in your form.
It is possible to use both GET and POST in form, just add appropriate attribute method to form tag:
<form action="index.php?page=5" method="POST">
So the pager links are submit buttons while rest of the data is stored in hidden fields. But that's not a good way to do this because you cannot pass someone link (on IM for example) to your search results.
But the best way is to store somewhere POST input data (look here: http://www.symfony-project.org/plugins/, when you input your query once, it is stored and remembered so you dont need to fill form multiple times)