Skip to content

Instantly share code, notes, and snippets.

@jbroadway
Created August 20, 2013 20:32
Show Gist options
  • Save jbroadway/6286885 to your computer and use it in GitHub Desktop.
Save jbroadway/6286885 to your computer and use it in GitHub Desktop.
Dynamically populated multiple select in an Elefant CMS form.
<!-- apps/test/views/multiple.html -->
<form method="post" id="{{_form}}">
<select name="type[]" multiple>
{% foreach options as val, label %}
<option value="{{val}}"{% if in_array ($data->val, $data->selected) %} selected{% end %}>{{label}}</option>
{% end %}
</select>
<input type="submit" value="Submit" />
</form>
<?php // apps/test/handlers/multiple.php
$form = new Form ('post', $this);
$form->data = array (
'options' => array (
'foo' => 'Foo',
'bar' => 'Bar',
'baz' => 'Baz'
),
'selected' => array ('bar', 'baz')
);
echo $form->handle (function ($form) {
info ($_POST);
});
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment