Display Zend_Form_Element_Radio on One Line

Display Zend_Form_Element_Radio on one line

You need to call the setSeparator method on the Zend_Form_Element_Radio object, passing it ''. Here's an example from here:

<?php     

class CustomForm extends Zend_Form
{
public function init()
{
$this->setMethod('post');
$this->setAction('user/process');
$gender = new Zend_Form_Element_Radio('gender');
$gender->setLabel('Gender:')
->addMultiOptions(array(
'male' => 'Male',
'female' => 'Female'
))
->setSeparator('');
}
}

how can set radio buttons horizontally in zend form

Did a quick search, maybe this post will help?

Display Zend_Form_Element_Radio on one line

From the old answer:

You need to call the setSeparator method on the Zend_Form_Element_Radio object, passing it ''.

Good luck!

Line Breaks in Options of Radio Form Element

you have to use custom zend form decorator with your current form

you can use below code and link to add

Also if you want to change any more html changes you can make it as your custom.

Align radio buttons horizontally

This question has been asked before
here, the accepted answer should show you how to go about this.

Edit:
Have you tried: array("listsep" => ' ')

It seems to be the universal solution, here is another example

Zend Radio Element Decorator

    $radio = new Zend_Form_Element_Radio('rating');
$radio->setLabel('Rating')
->addMultiOptions(array(
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5'
))
$radio->setSeparator(' ');

Zend 1 radio option as image

You need to set escape=false on the element, not just the decorator. Something like

$el = new Zend_Form_Element_Radio('radio', array(
'options' => $options,
'escape' => false, // <- this is the line
));

How would I format Zend_Form_Element_Radio so the label follows the input?

It's an issue with jQuery and not the Zend Framework. The wrapping of the element in the label tag is perfectly valid it's just jQuery UI doesn't support it. I have posted a bug report.

* Update Answer *

However I think what you are trying to do (as you commented) is to use the jQuery UI buttonset, which is what I was doing when I came across the jQuery UI bug. In short you have two options until the bug is fixed:

1) Use Dennis D.'s custom view helper to over ride the default radio button element.

2) Patch the Zend Framework Radio button view helper with the code Dennis D. has written. It appears in the file Zend_View_Helper_FormRadio on line 169 (Zend framework Version 1.11.0).

Firstly create a new label and close the tag

// Create the label
$label = '<label'
. $this->_htmlAttribs($label_attribs) . ' for="' . $optId . '">'
. (('prepend' == $labelPlacement) ? $opt_label : '')
. '<input type="' . $this->_inputType . '"'
. $opt_label
. '</label>';

Secondly alter the code that creates the radio button to:

// Create the radio button
$radio = '<input type="' . $this->_inputType . '"'

Thirdly remove the closing of the label tag (as you've already done it) in the view helper, change:

. $endTag
. (('append' == $labelPlacement) ? $opt_label : '')
. '</label>';

And simply replace with:

. $endTag;

Then combine the radio and the label using the placement positioning:

// Combine the label and the radio button
if ('prepend' == $labelPlacement) {
$radio = $label . $radio;
} else {
$radio = $radio . $label;
}

And that's it (again Dennis D has done it in the view helper) but the changed code should look like (starting at line 169:

// Create the label
$label = '<label'
. $this->_htmlAttribs($label_attribs) . ' for="' . $optId . '">'
. $opt_label
. '</label>';

// Create the radio button
$radio = '<input type="' . $this->_inputType . '"'
. ' name="' . $name . '"'
. ' id="' . $optId . '"'
. ' value="' . $this->view->escape($opt_value) . '"'
. $checked
. $disabled
. $this->_htmlAttribs($attribs)
. $endTag;

// Combine the label and the radio button
if ('prepend' == $labelPlacement) {
$radio = $label . $radio;
} else {
$radio = $radio . $label;
}
// add to the array of radio buttons
$list[] = $radio;

How to display radio Buttons one after the other in zend dojo form?

Try to replace

   ->setSeparator(' ');

by

   ->setSeparator('<br>');

Edit individual radio buttons in zend form view script

Figured this one out too. Just use

$this->element->getElment('myRadio')->getMultiOptions();

and it will return an array of the key/value options.



Related Topics



Leave a reply



Submit