TbHtml::radioButton PHP Method

radioButton() public static method

Generates a radio button.
public static radioButton ( string $name, boolean $checked = false, array $htmlOptions = [] ) : string
$name string the input name.
$checked boolean whether the radio button is checked.
$htmlOptions array additional HTML attributes.
return string the generated radio button.
    public static function radioButton($name, $checked = false, $htmlOptions = array())
    {
        $label = TbArray::popValue('label', $htmlOptions, false);
        $labelOptions = TbArray::popValue('labelOptions', $htmlOptions, array());
        $input = parent::radioButton($name, $checked, $htmlOptions);
        // todo: refactor to make a single call to createCheckBoxAndRadioButtonLabel
        if (TbArray::popValue('useContainer', $htmlOptions, false)) {
            return self::tag('div', array('class' => 'radio'), self::createCheckBoxAndRadioButtonLabel($label, $input, $labelOptions));
        } else {
            return self::createCheckBoxAndRadioButtonLabel($label, $input, $labelOptions);
        }
    }

Usage Example

Example #1
0
 public function testRadioButton()
 {
     $I = $this->codeGuy;
     $html = TbHtml::radioButton('radio', false, array('class' => 'input', 'label' => 'Label text'));
     $label = $I->createNode($html, 'label');
     $I->seeNodeCssClass($label, 'radio');
     $I->seeNodePattern($label, '/> Label text$/');
     $input = $label->filter('input[type=radio]');
     $I->seeNodeAttributes($input, array('class' => 'input', 'id' => 'radio', 'name' => 'radio', 'value' => '1'));
     $I->dontSeeNodeAttribute($input, 'checked');
     $html = TbHtml::radioButton('radio', true);
     $input = $I->createNode($html, 'input[type=radio]');
     $I->seeNodeAttribute($input, 'checked', 'checked');
 }
All Usage Examples Of TbHtml::radioButton
TbHtml