tags:

views:

71

answers:

5

Hello,

I face a problem whenever the user tries to browse to second page via $_GET if they have submitted $_POST data.

if(!isset($_POST['submit'])) {
//search input box
}
else {
//search details output
//pagination code
}

Whenever user press page 2, it shows //search input box back.

I want search to show page 2 and not //search input box back.

A: 

Seams like your logic is twisted. Just look at your code with aditional comments:

// if POST submit is NOT set
if(!isset($_POST['submit'])) {
   // show search input box
}
Frankie
+3  A: 

This is because you are not sending POST data to the second page.

$_GET and $_POST are set per request. If you want to save the first POST data, you will need to use sessions and store it in the session, or return the POSTed data to your page and have it be resubmitted.

Alan Geleynse
how would it be?
cicakman
How would it be what? As others have said, you will need to tell us a little more about what you are doing and what you want for us to help.
Alan Geleynse
+1  A: 

As @Alan says... page 2 isn't receiving POST data, so submit is not set and it thinks the starting form should be shown again. A second GET variable (eg page) to track the results-page, will allow all three pages (start, page1+submit, page2)

if (isset($_REQUEST["page"])) {
    //No data received, but reviewing & page-display code should go here
} elseif (isset($_POST["submit"])) {    
    //POST-processing code goes here
    // Page-switching URL should be something like:
    // <a href="results.php?page=2">Page 2</a>  
} else {
    //Nothing posted, not paging - show input
    //search input box
}

Don't forget to store your POST data somewhere temporarily so that you have data to display on the pages.

Rudu
A: 

You shouldn't be submitting a search request via POST. Searching is the kind of read-only operation ideally suited to GET requests and the query string. All you have to do then is modify the query string to include something like &page=2 to add pagination to your links.

meagar
A: 

A better way to do it is to split your form processing into its own script. This makes it more organized and more logical so that you can do things like POST to it via AJAX easier. A tip for solving the other problem I see you are having is if you are having a multipage form you should store the data they submit on previous pages somewhere. A common place is in session data. There are other ways to do it like storing it all in a javascript data object until the form is completed. Look into using a framework, they will help.

LLBBL