Skip to content

Commit

Permalink
Added the choose_from_radio() function to
Browse files Browse the repository at this point in the history
display groups of radiobuttons in a central way.
Part of bug 1430.
(http://moodle.org/bugs/bug.php?op=show&bugid=1430)

Merged from MOODLE_15_STABLE
  • Loading branch information
stronk7 committed Jun 27, 2005
1 parent 08de7c7 commit 531a3cb
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/weblib.php
Expand Up @@ -697,6 +697,43 @@ function choose_from_menu ($options, $name, $selected='', $nothing='choose', $sc
}
}

/**
* Given an array of values, creates a group of radio buttons to be part of a form
*
* @param array $options An array of value-label pairs for the radio group (values as keys)
* @param string $name Name of the radiogroup (unique in the form)
* @param string $checked The value that is already checked
*/
function choose_from_radio ($options, $name, $checked='') {

if (!$name) {
$name = 'unnamed';
}

$output = '<span class="radiogroup '.$name."\">\n";

if (!empty($options)) {
$currentradio = 0;
foreach ($options as $value => $label) {
$output .= ' <span class="radioelement '.$name.' rb'.$currentradio."\">";
$output .= '<input name="'.$name.'" type="radio" value="'.$value.'"';
if ($value == $checked) {
$output .= ' checked="checked"';
}
if ($label === '') {
$output .= ' />'. $value .'</span>' . "\n";
} else {
$output .= ' />'. $label .'</span>' . "\n";
}
$currentradio = ($currentradio + 1) % 2;
}
}

$output .= '</span>' . "\n";

echo $output;
}

/**
* Implements a complete little popup form
*
Expand Down

0 comments on commit 531a3cb

Please sign in to comment.