0

I have a radio button list with three options: daily, monthly, weekly. I want a way to access each one individually. For example:

echo $this->formElement($form->get('iteration')); 

Will print out all three values, with their labels:

[ ] daily
[ ] monthly
[ ] weekly

I want a way to iterate over all the elements. Something like this:

foreach ($this->formElements($form->get('iteration') as $element)  {
    echo $this->formElement($element); 
}

But that doens't work. Any thoughts?

1 Answer 1

2

When you're using the Zend\Form\Element\Radio form element with multiple options, you can iterate over the options like this:

foreach ($form->get('iteration')->getValueOptions() as $option) {
    ...
}

But if you want to output the options separately, you'd need to create multiple Zend\Form\Element\Radio's.

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.