[pmwiki-users] Default form markup questions...

Patrick R. Michaud pmichaud at pobox.com
Thu Aug 24 15:32:43 CDT 2006


On Thu, Aug 24, 2006 at 03:52:48PM -0400, The Editor wrote:
> Here's a stab at it...
> 
> > > I envision something > like:
> > > (:select <name> default="option2" value1|display1 value2|display2 etc :)
> > > or likewise
> > > (:radio <name> default="option2" value1 value2 etc :)
> >
> > What does "option2" refer to in each case?  And in the case of the
> > (:radio ...:) markup, what HTML output do you expect it to generate?
> 
> Example:
> 
> (:select State default="OK" TN|Tennessee NY|New York OK|Oklahoma:)
> 
> would produce
> 
> <select name="State">
> <option TN>Tennessee
> <option NY>New York
> <option OK selected>Oklahoma
> </select>

Interesting.  I'm not sure how I would split this -- simply splitting
on whitespace doesn't work because we'd end up with "NY|New" instead
of "NY|New York".  But it could be done.

> (:radio State default="OK" TN|Tennessee NY|New York OK|Oklahoma:)
> 
> would produce
> 
> <br><input type="radio" name="State" value="TN"> Tennessee
> <br><input type="radio" name="State" value="NY"> New York
> <br><input type="radio" name="State" value="OK" checked> Oklahoma

The first thing I'll hear from site administrators will be
"How can I change the <br> to be something else?  What if I want
the radio buttons to appear in a line, or in a table?"

> Though the default flag should be optional, allowing it would enable
> me to retreive and set data from a data page very easily, my goal in
> all this:
> 
> (:radio Fieldname default="{$Fieldname} ... :)

Hmm, let's back up a second and look at this from a totally different
perspective.

Currently PmWiki uses an $InputValues array to set the default
values for text controls.  So, if the markup has the following

    (:input text name=abc:)

then the value= parameter is taken from $InputValues['abc'].  This
makes it particularly easy to grab values from previously submitted
forms or urls, since local/config.php can do:

    $InputValues = $_REQUEST;

and this will automatically fill in the controls from a previous
request.  For example,  calling a page with the above markup and
a url like .../pmwiki.php?abc=Hello would result in form HTML of

    <input type='text' name='abc' value='hello' />

I've already been planning to extend $InputValues to do the
right thing for radio and checkboxes.  Thus

    (:input radio name=abc value=Aloha:) Aloha
    (:input radio name=abc value=Hello:) Hello
    (:input radio name=abc value=Bonjour:) Bonjour

with the above url would result in

    <input type='radio' name='abc' value='Aloha' /> Aloha
    <input type='radio' name='abc' value='Hello' checked='checked' /> Hello
    <input type='radio' name='abc' value='Bonjour' /> Bonjour

where the "Hello" button has already been checked because it's
the value of the 'abc' control in the $InputValues array.

So, what do we do when we want to set the default value of a control
based on markup as opposed to a PHP function, url, or POST?  The
easiest thing to do is create a markup for it (I'll use 'input default'
here):

    (:input default abc "{$SomeVar}":)
    (:input radio name=abc value=Aloha:) Aloha
    (:input radio name=abc value=Hello:) Hello
    (:input radio name=abc value=Bonjour:) Bonjour

This would cause the radiobox corresponding to the value of 
the page variable {$SomeVar} to be selected by default.

Similarly, from the proposed markup in PITS.00567:

    (:input default xyz "{$SomeOption}":)
    (:input select name=xyz "Option 1":)
    (:input select name=xyz "Option 2":)
    (:input select name=xyz "Option 3":)

would automatically generate a select box with the corresponding
option already set.  And of course this would work with
select lists generated from pagelists...

    (:input default xyz "HomePage":)
    (:pagelist fmt=#formlist:)

where fmt=#formlist could be used to generate a list
of any type of input box, whether they be checkboxes, radio
buttons, or a select list, and the default value(s) of the
corresponding xyz control would be marked accordingly.

This also gives us a way to deal with pre-filling in textareas, 
if we allow a bracketed form of (:input default:)...

    (:input default abc:)
    This is the default text for the textarea below
    (:input end:)

    ...
    (:input textarea abc:)

which would generate output of

    <textarea name='abc'>
    This is the default text for the textarea below
    </textarea>

Of course, existing values in the $InputValues array would generally
override values coming from the markup, so that previously entered
form data would override whatever is in the markup.

How's that for a solution?

> My suggestion is we keep "input" for all the simpler inputs (like the
> existing markups) and use the shorter names for more advanced markups.
> [...]
> It would be nice if all the markups, both simple and more complex were
> available in core.

I really don't want to support two different styles of form markup
in the core -- it gets a little too close to PmWikiPhilosophy #3
to me ("avoid gratuitous features").  

PmWiki offers *a* convenient and somewhat consistent mechanism for 
creating forms, primarily to answer "how to I create a form" sorts 
of questions and as a convenient syntax for generating various utility 
forms PmWiki needs such as Site.AuthForm and Site.EditForm.  There
are plenty of different and excellent ways to generate form controls,
so I've simply picked one mechanism that can cover a *lot* of cases
and left other approaches to recipes and other customizations.

I think the corollary to this is that it's fairly safe to assume
that PmWiki won't ever define (:select:), (:textarea:), (:radio:),
etc. markups in the core, so recipes are free to use them.  :-)

Pm




More information about the pmwiki-users mailing list