[pmwiki-users] Fun with forms - 3 ideas

Petko Yotov 5ko at free.fr
Thu Apr 19 19:40:25 CDT 2007


Sorry to not replying in the right thread, but I lost the first message...

This is a very nice recipe, I am very glad that Patrick did it, we can be sure 
it will work well and safely. As I've been tinkering with something like 
this, may I share some ideas?

1. We need some kind of form validation, or at least, a way to write a 
function that will intercept the posted data and decide to filter, sanitize, 
save it or not. 

Specifically:
* if the user is supposed to enter a float number, the function may perform a 
$_POST['ptv_myedit'] = floatval($_POST['ptv_myedit']); eventually replacing 
commas with dots;
* if the user enters a smiley ":)" in a text field, which is not improbable, 
and the input gets written inside a (:var:value:) PTV, it will break it -- 
so, I imagine an input of ":)" may be transformed into ":-)" and it will 
work.

This function may rely on the variable name, as in '$:intAmount' -> intval(); 
or on some special field in the form template ("Amount=int Price=float" etc.)

I am not saying that Patrick should write it, just to leave a door for such a 
usefull customization.

2. How about a new "action=editvars" without the need to define a form 
template in the URL, but from a special PTV in the edited page (or in the 
GroupHeader, etc.), like:

(:editform:Group.Page:)

3. Assuming that a new "action=editvars" appears, and there is no indication 
(:editform:Group.Page:) nor a template in the URL, the recipe creates a form 
to edit every PTV, one after another, shorter in "text", longer 
in "textarea".

  foreach($PCache[$pagename] as $k=>$v)
  {
    if(substr($k, 0, 3) != "=p_") continue;
    $varname = substr($k, 3);
    $InputValues["ptv_$varname"] = $v;
    if($editform) continue; // there is a template, do not build form

    $PageEditForm .= ": $varname : ";
    if(strpos( " $v", "\n") || strlen($v)>30) 
      $PageEditForm .= "(:input textarea $:$varname cols=60 rows=4:)";
    else $PageEditForm .= "(:input text $:$varname:)";
    $PageEditForm .= "\n";
  }

Thanks,
Petko






More information about the pmwiki-users mailing list