[pmwiki-users] fun with forms

Patrick R. Michaud pmichaud at pobox.com
Thu Apr 19 15:13:14 CDT 2007


On Thu, Apr 19, 2007 at 12:35:14PM -0700, Martin Fick wrote:
> --- "Patrick R. Michaud" <pmichaud at pobox.com> wrote:
> 
> >http://www.pmwiki.org/wiki/Cookbook/SimpleRating?action=edit&editform=Cookbook.RecipeInfoForm
> ... 
> > The form really does work -- if you change any of
> > the fields in the form and save, then the 
> > corresponding fields of the target page will change 
> > also.
> 
> One quick concern: namespaces.
> 
> Is it likely that someone might define a form element
> that happens to match a name of a PTV in the page
> without realizing it?  

Possible, yes; likely -- I dunno.  I'm guessing not very
likely in the general case.  As you noted, the ptvs are 
replaced only if the (hidden) control ptvreplace is set.

> In other words, should there be a mechanism to
> explicitly indicate that a specific field should be
> replaced?  

It wouldn't be difficult to amend 'ptvreplace' to identify
only the form elements that are to be changed (or possibly
excluded).  This could even be done with wildcard matching:

    (:comment only replace fields beginning with S, excluding
      "Special" and "Secret":)
    (:input hidden ptvreplace S*,-Special,-Secret:)

Another possibility is to prefix the elements in the form
with "ptv_" or something like that.... but that's a bit
less elegant.

Another possibility is to change 'ptvreplace' to 
'ptvprefix' which identifies the prefix to be used for
form controls that are intended to edit PTVs.
Or it could be a configuration variable.

Or something like that.  

> This could particularly be an issue
> with external recipes that may want to piggy back off
> of this mechanism that need some other form elements
> defined.

I think I'd need to see an example of piggybacking.
But the code that does the replacements is actually
just a couple of variable settings in $ROEPatterns
(performed only when $_POST['ptvreplace'] is set),
so they could easily be disabled, replaced, or
circumvented by a piggybacking recipe that wants to do 
something substantially different or avoid conflicts.

Pm



More information about the pmwiki-users mailing list