Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

Handling multi-valued fields

edited September 2015 in Framework

Does elefant have predefined methods to handle fields than can have multiple values such as checkboxes or select multiples?

This is what I'm doing at the moment.

In the handler before loading the form:

$form->data = new businesses\Business ($_GET['id']);
$form->data->category = explode ('; ', $form->data->category);

In the handler before saving the form:

$business->category = implode ('; ', $_POST['category']);

In the view:

<select multiple name="category[]">
    <option value="">- select -</option>
{% for _key in categories %}
    <option value="{{_key|quotes}}"{% if in_array($data->_key, $data->category) %} selected{% end %}>{{_key}}</option>
{% end %}


Sign In or Register to comment.