[pmwiki-devel] Select & Option Dropdown-list Markup

The Editor editor at fast.st
Mon Dec 11 11:36:48 CST 2006

On 12/11/06, Hans <design5 at softflow.co.uk> wrote:
> I am seeking some advise how to optimise some markup, and choose
> good markup names.
> The following are three markup definitions to produce <select>
> <option> ... </option> and </select> tags. This in turn will provide a
> dropdown selection box, which could be used in input forms and other
> places. The markup is pretty basic and perhaps too general.
> /*  (:select name [jsgoto]:)
> This will produce a name and id for the select HTML tag.
> jsgoto is optional, and when present the function will return a select
> tag with an added hard-coded onchange javascript bit. This is useful
> when selecting page urls, as by selecting you immediately will be
> directed to the page selected, without having to click a submit button.
> In conjunction with pagelist you can very simply build a dropdow menu
> of pages of the current group for instance (see code below), as a
> instant jump-to box. */
> Markup('select', 'directives', '/\\(:select\\s+(.*?)\\s*(jsgoto|):\\)/e',
>       "Keep(SelectMarkup(\$pagename, '$1', '$2'))");
> function SelectMarkup($pagename, $id, $arg2 ) {
>   if($arg2=='jsgoto')
>      return "<select name='$id' id='$id'
>        onchange='window.location.href=this.options[this.selectedIndex].value' >";
>   else return "<select name='$id' id='$id' >";
> }
> /*  (:option value label:)
> This will generate option tags with value and label provided. If no
> label text is specified, value will be used instead.  */
> Markup('option', 'inline', '/\\(:option\\s+(.*?)\\s+(.*?)\\s*:\\)/e',
>       "Keep(OptionMarkup(\$pagename, '$1', '$2'))");
> function OptionMarkup($pagename, $val, $label) {
>    if($label=="") $label = $val;
>    return "<option value='$val' />$label</option>";
> }
> /*  (:selectend:)
> This closes the option list.  */
> Markup('selectend', 'inline', '/\(:selectend:\\)/e',
>       "Keep('</select>')");
> I got a drop-down page selection menu using pagelist
> by adding this to Site.LocalTemplates:
> !!!fmt=#selectmenu
> drop-down page selection box
> [@
> [[#selectmenu]]
> (:option {$ScriptUrl}?n={=$FullName} {=$Title}:)
> [[#selectmenuend]]
> @]
> and putting into Site.SideBar:
> (:input form action={*$PageUrl}:)
> (:select menupage jsgoto:)
> (:pagelist group={*$Group} fmt=#selectmenu :)
> (:selectend:)
> (:input submit post "Go to Page":)
> (:input end:)
> The part from (:select menupage .. to (:selectend:) works on its own
> with the javascript goto. To have it working with  a form submit button
> it needs the (:input form .. surrounding it, and an additional php condition
> to handle the redirection (added in config.php):
> # pick up 'menupag' selection from (:select  :) on submit
> if(isset($_POST['menupage']))
>    Redirect ($_POST['menupage']);
> This could become a recipe perhaps, but I like to optimise the code,
> and check for pitfalls, overlaps, security bugs, with your help
> please!
> I am aware that we may get one day an (:input select... ) markup, and
> I played with a version for that first, before going with the close to
> HTML terminology, as it makes the markup-writing for authors a bit
> shorter.
> --
> Best,
>  Hans

For what it's worth Hans, here is the markup used in zap.  Very similar:

Markup('select', 'inline', '/\(:select (.*?):\\)/', '<select name=$1>');
ie (:select FieldName:)

Markup('select+', 'inline', '/\(:select\\+ (.*?):\\)/', '<select
name=$1 onChange="window.location=this.options[this.selectedIndex].value">');
ie (:select+ FieldName:)

Markup('option', 'inline', '/\\(:option (.*?):\\)/e', "Keep('<option
'.PQA(PSS('$1')).' />')");
ie (:option value="MyValue":)Display Value

Markup('selectend', 'inline', '/\(:selectend:\\)/', '</select>');

I may not have done the best with these but they do work.  I use the
same pagelist technique as yours for a dynamic jump menuo on the
zapsite for the snippets.

I don't know if there will be errors for anyone using your markups
when they are also defined in zap (we use the same id's) or if one
will simply overwrite the other.  Or I could change mine to zapselect,
etc.  Also not sure if we should try to use the same syntax (I'd be
happy to make improvements if there are problems with my code, though
I think Pm has looked at them for security risks). And it's pretty
straightforward also--just slightly different.  Of course we should
have these markups available separately for those who don't need all
the other stuff in zap, but it would be nice if they were the same. Or
we could just have two options out there and wait until Pm introduces
the new forms script (slated for this beta series) which will likely
make both ours obsolete.  =|: )


More information about the pmwiki-devel mailing list