[pmwiki-devel] Select & Option Dropdown-list Markup
Hans
design5 at softflow.co.uk
Mon Dec 11 11:14:29 CST 2006
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
More information about the pmwiki-devel
mailing list