[pmwiki-users] Fun with forms - 3 ideas

Hans design5 at softflow.co.uk
Fri Apr 20 04:07:18 CDT 2007


Friday, April 20, 2007, 9:27:24 AM, Petko wrote:

> It is already possible to hook it this way:

>   array_unshift($EditFunctions, "MyPreProcessor");
>   function MyPreProcessor($pagename,&$page,&$new)
>   {
>     global $EnablePost;
>     if (!$EnablePost) return;
>     # is there our trigger form field? 'foxfilter' or whatever
>     if(! isset($_POST['_prefilter']) ) return;
>     $filters = explode(',', $_POST['_prefilter']);
>     # Do the pre-processing, ie.:
>     foreach($_POST as $key=>$value)
>     {
>        # test and sanitize
>     }
>   }

Oh thanks! Below is a version which uses an $EditFilterFunctions
array, so recipes can just add

$EditFilterFunctions['myfilter'] = 'MyFilterFunction';
function MyFilterFunction($pagename, $_POST) {
  ...do the $_POST field manipulations here...
  return $_POST;
}


array_unshift($EditFunctions, "EditPreFilter");

function EditPreFilter($pagename,&$page,&$new) {
   global $EnablePost, $EditFilterFunctions;
   if (!$EnablePost) return;
   // check for filter field
   if(! isset($_POST['editfilter']) ) return;
   $filters = preg_split("/[\s,|]+/", $_POST['editfilter'], -1, PREG_SPLIT_NO_EMPTY);
   foreach($filters as $filter) {
      $fifn = $EditFilterFunctions[$filter];
         if (function_exists($fifn) ) {
            if(is_callable($fifn, false, $callable_name)) {
               $_POST = $callable_name($pagename, $_POST);
               if(!$fields) Redirect($pagename); // Filter is telling us to abort;
            }
        }
  }

I am not sure if it is okay to manipulate $_POST directly. It also
excludes $_GET, so that is not good. Fox converts $_POST first to an
internal $fields array, which then gets passed to the filter functions.

So my original question may be changed to say:

Can we have an improved version of such an EditPreFilter function in
the PmWiki core? Because then recipes would not need to add each their own
version, which will basically all be the same with a different
function name.

Or add some similar functionality?


  ~Hans




More information about the pmwiki-users mailing list