How do you build up checkboxes as arrays

william - 3 weeks ago

Example
If i build a form like so:

{% set form = form ({
    'handler': '[email protected]',
    '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">

Answer

- 3 weeks ago

This is how you do it:

{% set form = form ({
    'handler': '[email protected]',
    '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

william - 3 weeks ago

This is how you do it:

{% set form = form ({
    'handler': '[email protected]',
    '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