-
Notifications
You must be signed in to change notification settings - Fork 1
multiselect
fireproofsocks edited this page Oct 8, 2014
·
7 revisions
Similar to the dropdown field element, but this (and the multicheck) element allows users to select an array of options.
Syntax: multiselect($name,$options=array(),$values=array(),$args=array(),$tpl=null)
Note that the default formatting template (tpl) for multiselect fields defines an array input: name="[+name+][]"
so you do not need to include "[]" as part of your $name argument.
<?php
print \Formbuilder\Form::multiselect('genre',
array('Scifi','Fiction','Horror','Romance'));
?>
The array keys are submitted as form values: the array values are shown as labels.
<?php
print \Formbuilder\Form::multiselect('genre',
array('sci'=>'Scifi', 'fic'=>'Fiction',
'hor'=>'Horror', 'rom'=>'Romance'));
?>
This is useful for labeling database records.
Just as with the dropdown() and multicheck() fields, you can pass nested data to a multiselect field to specify option groups:
<?php
$options = array(
'Birds' => array(
'bluebird' => 'Sad Bluebird',
'crow' => 'Black Crow',
),
'Mammals' => array(
'cow' => 'Mute Cow',
'dog' => 'Good Dog',
)
'Reptiles' => array(
'croc' => 'Crocodile',
'turtle' => 'Slow Turtle',
)
);
print \Formbuilder\Form::multiselect('categories',$options);
?>
More deeply nested structures are not supported.
© 2014 and beyond by Craftsman Coding