How do you build up checkboxes as arrays
Created 6 years ago by william

Example
If i build a form like so:

{% set form = form ({
    'handler': 'MyHandler@handle',
    'ajax': true,
    'options': {
    'redirect': false,
    },
    'fields': {

    }
}).get() %}

What do i specify within fields to have the following output?

Expected Output

<input type="checkbox" name="checkboxarray[]" value="value1">
<input type="checkbox" name="checkboxarray[]" value="value2">
william  —  6 years ago Best Answer

This is how you do it:

{% set form = form ({
    'handler': 'MyHandler@handle',
    'ajax': true,
    'options': {
    'redirect': false,
    },
    'fields': {
        'checkboxarray': {
                'type': 'checkboxes',
                'required': true,
                'options': {'value1':'title1','value2':'title2'},
            }
    }
}).get() %}

<input type="checkbox" name="checkboxarray[]" value="value1"> title1
<input type="checkbox" name="checkboxarray[]" value="value2"> title2