0

When adding elements to a Zend 2 Form,

  foreach($headers as $column)
            {
                $checkbox = new Element\Checkbox('checkbox');
                $checkbox->setLabel($column . "");
                $checkbox->setUseHiddenElement(true);
                $checkbox->setCheckedValue("true");
                $form->add($checkbox);
            }

I run into the problem that only the last element is added. From stepping through the code, I know that it is running the loop multiple times, but the add() code of the Zend Form just seems to map the last element rather than add all of the elements. What's the best way to do something like this?

1 Answer 1

2

You need to give each element a unique name rather than just 'checkbox'.

Try this:

$checkbox = new Element\Checkbox($column);
Sign up to request clarification or add additional context in comments.

Comments

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.