I write “report” pages all the time. These pages usually consist of some kind of filterable elements at the top with the results below. When the user fills out a filter element such as “status”, they expect that value to be retained when the page refreshes. And if he/she is going to proceed to the second “page” of results, that filter should still remain in place.

Pasted below is little code that helps maintain “sticky” filters, swap out bits and pieces as necessary for your reporting. This is obviously a really simple example that doesn’t have a lot of the UI elegance you’d put into a real report, but I think the point is made that storing the filtered elements into a session array is the easiest way to make them “stick” between page loads.

$sesParams = &$_SESSION['session_reportName'];
if(!is_array($sesParams)) {
	$sesParams = array();
if(isset($_REQUEST['newParams']) || isset($_REQUEST['clear'])) {
	$sesParams = array();
	$fieldsToGet = array(	'date_from',
	foreach($fieldsToGet AS $fieldName) {
		$sesParams[$fieldName] = $_REQUEST[$fieldName];

<form action="<?=$_SERVER['PHP_SELF']?>" method='post'>
	<input type='hidden' name='newParams' value='true'>
	<table class='body10'>
				<input type='text' name='date_from' value="<?=$sesParams['date_from']?>">
				<input type='text' name='date_to' value="<?=$sesParams['date_to']?>">
				<input type='text' name='status' value="<?=$sesParams['status']?>">
				<input type='submit' value='Filter' class='input10'>
				<input type='button' value='Clear' class='input10' onclick="window.location='<?=$_SERVER['PHP_SELF']?>?clear'">

May 3rd, 2013

Posted In: Shortcuts, User Interface

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: