Reputation: 153
I want the following HTML:
<form name="input" action="post" method="get">
<label>1</label><input type="radio" value="1" name="rating" />
<label>2</label><input type="radio" value="2" name="rating" />
<label>3</label><input type="radio" value="3" name="rating" />
<label>4</label><input type="radio" value="4" name="rating" />
<label>5</label><input type="radio" value="5" name="rating" />
<input type="submit" value="Submit" />
</form>
In my zend framework project, how do I do this with Zend_Form? I have tried a few sample bits of code from certain blogs but they don't work..
Thanks
Upvotes: 1
Views: 1829
Reputation: 968
You can use the ViewScript decorator to create the markup that you need. In your form class create the radio element and use the setDecorators method to assign the viewscript decorator for this element
$element = new Zend_Form_Element_Radio('rating');
$element->addMultiOptions(array(
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5'
))
->setDecorators(array(array('ViewScript', array('viewScript' => 'radio.phtml'))));
$this->addElement($element);
then create the file radio.phtml inside your views/scripts directory with the following
<?php foreach ($this->element->getMultiOptions() as $label => $value) : ?>
<label><?php echo $label; ?></label><input type="radio" value="<?php echo $value; ?>" name="<?php echo $this->element->getName(); ?>" />
<?php endforeach; ?>
Upvotes: 6