[pmwiki-users] Multiple checkboxes

Hans Bracker design at softflow.co.uk
Thu Sep 24 05:42:51 CDT 2015


> Using a simple explode() with a separator is very easy but what happens
> if one of the values contains the separator?

> Also, the current markup for all input elements:

>    (:input ELEMENT name 1,2,3,4,somevalue:)

> means that the "value" argument in the HTML input tag is 
> "1,2,3,4,somevalue". It is not very consistent to have ONE way to define
> a value in (:input text name value:), (:input checkbox name value:) or
> any other element, and ANOTHER in (:input default name value:).

I agree. I also think it may be too much to push the array concept
too far when we want to save arrays in simple PTVs.
Since the space separator works well enough with (:input default:),
as illustrated with your example, it may be best to leave it at that.

I will publish a fox.php version, which will use space as separatot
when saving array values in a PTV, by default. And have an optional
$FoxPTVArraySeparator variable, which can be set to "," or other
separator character strings.

I also found a way to have checkboxes reflect the values in such a
PTV, by using a simple markup expression to clean up the PTV for use
with spaces in (:input default .. :), like in this form example:

(:foxmessages:)
(:fox frm ptvtarget=Main.WikiSandbox ptvfmt=text :)
(:input default $:Hobby[] {(foxcleanptv "{$:Hobby}")} :)
(:input hidden $:Hobby " ":)
(:input checkbox $:Hobby[] Travels:) Travels
(:input checkbox $:Hobby[] Photo:) Photography
(:input checkbox $:Hobby[] Music:) Music
(:input submit post:)
(:foxend frm:)

The markup expression defined in config.php:

$MarkupExpr['foxcleanptv'] = 'FoxCleanPTV($args[0])';
function FoxCleanPTV($arg) {
        global $FoxPTVArraySeparator;
        $pat = '/'.$FoxPTVArraySeparator.'/';
        return preg_replace($pat," ",$arg);
}

This seems to work well with various separators, and the PTV can look
for instance like these, in simple text PTVs:

Hobby: Travels,Photo,Music
Hobby: Travels, Photo, Music
Hobby: Travels + Photo + Music


Best regards,
 Hans                         
mailto:design at softflow.co.uk
www.softflow.co.uk




More information about the pmwiki-users mailing list