I have a clientvendor.php file with various filters in it. This file directs to updateclientvendor.php file.

Now updateclientvendor.php has a Back button to go back to clientvendor.php . When the back button is pressed, I want the page to go back and display the filtered information which is not displayed when i use header( 'Location: clientvendor.php' ).

How can i store the contents of the filtered page when pressing back button !

I am filtering clientvendor.php based on 2 parameters : SelectType and SelectStatus. And then the user has to press Filter button to get the effect !

I think this could be a possible option !

In updateClientVendor.php save the filters and modify the link of the back button to send the filters back to the previous page (on the URL as GET params, i.e. clientvendor.php?filter1=&filter2=) when they go back.

My appraoch : (UpdateClientVendor.php)

$filtertype =$_POST['SelectType'];
$filterstatus =$_POST['SelectStatus'];

if(isset($_POST['Back']))
{
//URL ... So What should the URL be?
}

What should the URL be?

Dani AI

Generated

Short answer: the redirect string in your header was the issue. Two common mistakes are (1) using single quotes so PHP does not expand $filtertype, and (2) using the HTML entity & instead of a raw & in the Location header. Build the query properly (and urlencode values) and call header() before any output, then exit.

A robust way to build the back URL:

$qs = http_build_query([
  'SelectType'   => $filtertype,
  'SelectStatus' => $filterstatus,
  'Filter'       => 'true'
]);
header("Location: clientvendor.php?$qs");
exit;

On clientvendor.php, read the GET values, sanitize them, use them to run the filter automatically (if Filter is present), and pre-select the form controls when rendering:

$selectType   = isset($_GET['SelectType']) ? htmlspecialchars($_GET['SelectType']) : '';
$selectStatus = isset($_GET['SelectStatus']) ? htmlspecialchars($_GET['SelectStatus']) : '';

if (!empty($_GET['Filter'])) {
  // call your filtering function with $selectType and $selectStatus
}

Example for preserving the selected option in the HTML form:

<option value="client"<?php if ($selectType === 'client') echo ' selected'; ?>>Client</option>

Alternatives and troubleshooting:

  • Use $_SESSION to store filters if you prefer not to expose values in the URL (start the session, save on submit, then redirect back).
  • Check for "headers already sent" with headers_sent() or enable error reporting; stray whitespace before <?php will break header redirects.
  • To debug, echo the URL string before calling header() to confirm the query, or view the network request in browser devtools.

Notes tied to the thread: pointed you in the right direction with passing params in the URL; is correct that clientvendor.php should accept GET (and POST) and normalize inputs. The code above shows a safe, working way to implement both suggestions.

Recommended Answers

All 5 Replies

$url = "clientvendor.php?filter1=$filtertype&filter2=$filterstatus";

Thanks for your help !

UpdateClientVendor.php

$filtertype =$_POST['SelectType'];
$filterstatus =$_POST['SelectStatus'];

if(isset($_POST['Back']))
				{
				 header( 'Location: clientvendor.php?SelectType=$filtertype&SelectStatus=$filterstatus&Filter=true' ) ;
				}
			    ?>

Here SelectType and SelectStatus are two lists in clientvendor.php and Filter is the name of the button to click in order to filter the display !

But its still not working. Where is the problem? Is there some code to be included in clientvendor.php?

Please help me !

Aditi,

There is a number of ways to do this and your suggested method is probably the way I would do it.

It looks like you need two be able to accept parameters passed by $_POST and $_GET methods:

$_POST - For when a form is originally submitted (probably but not necessarily)
$_GET - For interpreting "back" button's url

You can use code like this to convert parameters to regular php variables, whilst allowing $_POST to override $_GET, in case there is a conflict:

<?php
// String params
$params = array('url' => 'u', 'title' => 't', 'action' => 'a');//hash of expected string parameters
while( list($var, $param) = @each($params) )
{
	if(isset($_POST[$param]) || isset($_GET[$param]))
	{
		$$var = (isset($_POST[$param]) ? htmlspecialchars($_POST[$param]) : htmlspecialchars($_GET[$param]);
	}
	else
	{
		$$var = '';
	}
}

// integer params
$params = array('uid' => 'uid', 'sid' => 'sid', 'itemid' => 'item');//hash of expected integer parameters
while( list($var, $param) = @each($params) )
{
	if(isset($_POST[$param]) || isset($_GET[$param]))
	{
		$$var = (isset($_POST[$param]) ? intval($_POST[$param]) : intval($_GET[$param]);
	}
	else
	{
		$$var = -1;
	}
}

// boolean params
$params = array('emailAlert' => 'email', 'cancel' => 'Cancel', 'submit' => 'Submit');//hash of expected boolean parameters
while( list($var, $param) = @each($params) )
{
	if(isset($_POST[$param]) || isset($_GET[$param]))
	{
		$$var = true;
	}
	else
	{
		$$var = false;
	}
}

?>

Airshow

I am still unable to go back to the searched criteria page using $_GET.

Can anyone give me a detailed description of how to do this relating it with my case? It would be of great help !

Aditi_19,

Build the back button's url as pritaeas says above and read parameters from $_GET and $_POST as I say above. Modify my code to read the parameters you are interested in (SelectType, SelectStatus, Filter), I can't give you the complete code because I don't know what the data types are (string|integer|boolean), but it is very easy to insert your parameters into my code, and to delete any of the code blocks that you don't use.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.