[geeklog-devel] How to use COM_applyFilter

Blaine Lang geeklog at langfamily.ca
Thu Feb 26 14:01:53 EST 2004


Dirk,

This is a good discussion and one we spent a lot of time in our code
addressing. I have been using your function and variations of it now for a
couple months. I think it's a great addition to the common functions.

I had a reason (can't recall the details now) where I added the option to
"not return 0" - it would return '' instead. The default was return for a
numeric test and the parameter being tested turned out to not be numeric.
 COM_ApplyFilter( $parameter, $isnumeric = false ,$returnzero=true)

The other purpose I had was a stronger version that only allowed "letters
and numbers"
     $p = preg_replace('/^[^(0-9a-zA-Z)]+/','', $parameter );


Plugin developer either not support versions prior to 1.3.9 or need to add
their own plugin version.

I often use the same variable name for GET and POST for something like "what
operation" is being performed. Sometimes you have links which trigger an
operation but in the same application there may be a form. I have been using
$op to indicate the operation (add/delete/edit etc ...) and use code like
this:

if (isset($HTTP_POST_VARS['op']) ) {
    $op = clubApplyFilter($HTTP_POST_VARS['op']);
} elseif (isset($HTTP_GET_VARS['op']) ) {
    $op = clubApplyFilter($HTTP_GET_VARS['op']);
} else {
    $op = '';
}

I first check the POST for a request and then the GET string. This is a
repeatitive piece of code as I may have other common used variables like
recid, mode, page, sortoption etc. Example: Page navigation needs to pass
page# and Sort options in the URL string but I also need to pass these
variable in forms if I want to return the user to same view.

I have been thinking, it would be nice to be have a common function that
would filter all the POST and GET vars. It is possible to walk the arrays
and maybe send it a list of variables to clean  - using array_walk().

Cheers,
Blaine




More information about the geeklog-devel mailing list