Hidden options of Zend_View_Helper_FormRadio

Logo Zend Framework

The documentation of Zend Framework view helpers is a little summary, we have to dig into source code to discover all the possibilities.

Take for example formRadio for creating radio buttons. The signature of this view helper is as follows:

<?php
function formRadio(
    
$name
    
$value null
    
$attribs null,
    
$options null,
    
$listsep "<br />\n"
)
?>

The phantom argument

The argument listsep not documented sets the HTML code to be inserted between each radio button. By default it is initialized with a newline, so the radio buttons appear on a column. If we want all the buttons on the same line, we have to pass an empty string.

"Magic" attributes

You can also set the separator by passing it in the argument $attribs.

escape argument is another "magic" attribute which ensures that the label of the options will be escaped.

Finally, there is the attribute disable that will disable all the options if set to true or just some options from their keys in an array.

<?php
// Disable option 1
echo $this->formRadio(
    
'option'
    
0
    array(
        
'disable' => array(0)
    ), 
    array(
'Option 1''Option 2')
);
?>

Customs labels

You can define the attributes of label by passing in $attrib with the prefix label_ or label .

<?php
// Add a CSS class radio
echo $this->formRadio('option'0, array('label_class' => 'radio'), 
    array(
'Option 1''Option 2')
);
?>

Output the following HTML code:

<label class="radio" for="option-0">
    <input name="option" id="option-0" value="0" checked="checked" type="radio">
    Option 1
</label>
<br>
<label class="radio" for="option-1">
    <input name="option" id="option-1" value="1" type="radio">
    Option 2
</label>

Etiquettes:

Add new comment