vietean
vietean

Reputation: 3033

How to render a Zend_Form_Element_MultiCheckbox form an array?

I need to render a MultiCheckbox like below:

Wanted:

<label>
    <input type="checkbox" name="privacy[read_only]" value="1" /> Just for read only
</label>
<label>
    <input type="checkbox" name="privacy[is_pulic]" value="1" /> Is public
</label>

How can I do that? I just can do with:

Unwanted:

<label>
    <input type="checkbox" name="privacy[]" value="read_only" /> Just for read only
</label>
<label>
    <input type="checkbox" name="privacy[]" value="is_pulic" /> Is public
</label>

Thanks so much for any your ideas.

Upvotes: 0

Views: 324

Answers (1)

Adam
Adam

Reputation: 5141

If there was nothing else in your form, or you didn't mind each form element having the same format, you could use setElementsBelongTo($array) which is a method on a Zend_Form.

You might also then have to use individual checkboxes to acheive the desired markup, so this may or may not work in your scenario.

Upvotes: 1

Related Questions