1

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

2
  • 1
    What did you try exactly and why didn't they work? Commented May 3, 2012 at 14:29
  • I tried this zendguru.wordpress.com/2009/03/05/… and i get the error -> setSeperator is not a function. Commented May 3, 2012 at 14:43

1 Answer 1

6

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; ?>
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.