0

I know I can create a form multi checkbox using new Zend_Form_Element_MultiCheckbox(). I'm not using this syntax however. I'm using the form view helper syntax in the view, like so:

echo $this->formMultiCheckbox('boxes', null, null, $possible_vals_array, null);

My question is how do I, using this syntax, add an array for the values that need to be checked by default?

1 Answer 1

1

The second parameter of $this->formMultiCheckbox() should be an array of values to have checked.

So if you your $possible_vals_array looks like this:

$possible_vals_array = array(
    'Value A' => 'Label A',
    'Value B' => 'Label B',
    'Value C' => 'Label C',
);

... and say you want to have values A and C checked by default, you'd pass an array like this as the second parameter:

$checked_vals_array = array('Value A', 'Value C');

So your call to the helper would look like this:

echo $this->formMultiCheckbox(
    'boxes', $checked_vals_array, null, $possible_vals_array, null
);
Sign up to request clarification or add additional context in comments.

3 Comments

Whoops. I guess the options array should be an associative array of option values and labels. I updated the answer to reflect that.
And when I say "options array", I mean $possible_vals_array.
Thanks so much. That was it. I wasn't using an associative array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.