| Index
» Projects
» phpMyEdit
» Forum
» Filter Problem |
 |
Taffman
Joined: 09 May 2014
Posts: 5
Posted: 2014-05-09 11:21
Back to top
Reply with quote
|
Hi, I have a page where the user name I want to use in a table filter is sent to the page from form data using the GET POST method.
The form sends the username to this script and sets via $_POST["name"]
I have set the following variable in my script:
$call_query = $_POST["name"];
I have set a filter as follows:
$opts['filters'] = 'PMEtable0.oper = "'.$call_query.'"';
This works and the table is displayed correctly filtered.
However if I try and sort, filter or search on this table no records are returned. It's as if the $user_name is lost once the table has been rendered.
I have read that there is an option called persist that may help here but I don't seem to be able to get that to work. This is what I'm using:
// Make valid_user persistent
$opts['cgi']['persist'] = array('PMEtable0.oper' => $call_query);
Any help in getting this to work would be much appreciated.
|
doug
Joined: 10 Feb 2003
Posts: 1013
Location: Denver, Colorado (USA)
Posted: 2014-05-09 19:54
Back to top
Reply with quote
|
An example using sessions to store a value:
// If your user session ID is set as $_SESSION['user_id'] then
if(!empty($_SESSION['user_id'])){
$opts['cgi']['persist'] = array('user_id' => $_SESSION['user_id']);
}
|
Taffman
Joined: 09 May 2014
Posts: 5
Posted: 2014-05-10 19:51
Back to top
Reply with quote
|
Hi Doug, thanks for the reply. I'm not using sessions. All Im trying to do is use html get post from a form to pass a name to pgpMyEdit and use that name in a filter to filter the records displayed. This works but the filter value passed in $_POST["name"] ios not persistent i.e. records are lost if I attempt to use navigation, sort or filter.
|
doug
Joined: 10 Feb 2003
Posts: 1013
Location: Denver, Colorado (USA)
Posted: 2014-05-10 20:20
Back to top
Reply with quote
|
$call_query is empty following any action because you are not using sessions, thus you should be using sessions to store the value.
|
Taffman
Joined: 09 May 2014
Posts: 5
Posted: 2014-05-10 21:10
Back to top
Reply with quote
|
Ok so in your example, do I replace 'user_id' with $call_query?
|
doug
Joined: 10 Feb 2003
Posts: 1013
Location: Denver, Colorado (USA)
Posted: 2014-05-10 23:54
Back to top
Reply with quote
|
Much of my work with persistent variables is done using sessions. I can't quickly locate a non-sessions based example in my recent work. Sessions would be useful if tracking the user ID of the logged in user, and restricting them to viewing ONLY those records which are associated with their ID.
So try instead:
// insecure
// $name = $_POST["name"];
// more secure, works with either GET or POST
$name = array_key_exists('name', $_REQUEST) ? @get_magic_quotes_gpc() == 1 ? trim(stripslashes(strip_tags($_REQUEST['name']))) : trim(strip_tags($_REQUEST['name'])) : '';
if($name != ''){
$opts['filters'] = 'PMEtable0.oper = "'.$name.'"';
$opts['cgi']['persist'] = array('name' => $name);
}
|
Taffman
Joined: 09 May 2014
Posts: 5
Posted: 2014-05-19 13:17
Back to top
Reply with quote
|
This works great, many thanks for your help.
|
|
Post new topic
Reply to topic
|
|
|
|