mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Adding patch from #2791
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5330 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
03ea2b8287
commit
bf5fc48087
1 changed files with 46 additions and 0 deletions
|
@ -675,6 +675,52 @@ class FormHelper extends AppHelper {
|
|||
$output .= sprintf($this->Html->tags['checkbox'], $this->model(), $this->field(), $this->_parseAttributes($options, null, null, ' '));
|
||||
return $this->output($output);
|
||||
}
|
||||
/**
|
||||
* Creates a set of radio widgets.
|
||||
*
|
||||
* @param string $fieldName Name of a field, like this "Modelname/fieldname"
|
||||
* @param array $options Radio button options array
|
||||
* @param array $inbetween String that separates the radio buttons.
|
||||
* @param array $attributes Array of HTML attributes.
|
||||
* @return string
|
||||
*/
|
||||
function radio($fieldName, $options, $inbetween = null, $attributes = array()) {
|
||||
|
||||
$this->setFormTag($fieldName);
|
||||
$attributes = $this->domId((array)$attributes);
|
||||
$this->__secure();
|
||||
|
||||
if ($this->tagIsInvalid()) {
|
||||
$attributes = $this->addClass($attributes, 'form-error');
|
||||
}
|
||||
|
||||
if (isset($attributes['type'])) {
|
||||
unset($attributes['type']);
|
||||
}
|
||||
|
||||
$value = isset($attributes['value']) ? $attributes['value'] : $this->value($fieldName);
|
||||
$out = array();
|
||||
|
||||
$count = 0;
|
||||
foreach ($options as $optValue => $optTitle) {
|
||||
$optionsHere = array('value' => $optValue);
|
||||
|
||||
if(empty($value) && $count == 0) {
|
||||
$optionsHere['checked'] = 'checked';
|
||||
} else if (!empty($value) && $optValue == $value) {
|
||||
$optionsHere['checked'] = 'checked';
|
||||
}
|
||||
|
||||
$parsedOptions = $this->_parseAttributes(array_merge($attributes, $optionsHere), null, '', ' ');
|
||||
$individualTagName = $this->field() . "_{$optValue}";
|
||||
$out[] = sprintf($this->Html->tags['radio'], $this->model(), $this->field(), $individualTagName, $parsedOptions, $optTitle);
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
$out = join($inbetween, $out);
|
||||
return $this->output($out ? $out : null);
|
||||
}
|
||||
/**
|
||||
* Creates a text input widget.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue