aboutsummaryrefslogtreecommitdiff
path: root/views/default/input/radio.php
blob: c897b48f18ebb3d9b460293d510545e095696242 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
 * Elgg radio input
 * Displays a radio input field
 *
 * @package Elgg
 * @subpackage Core
 *
 * @uses $vars['value'] The current value, if any
 * @uses $vars['js'] Any Javascript to enter into the input tag
 * @uses $vars['internalname'] The name of the input field
 * @uses $vars['options'] An array of strings representing the options for the radio field as "label" => option
 *
 */

$defaults = array(
	'class' => 'elgg-input-radio',
);

$vars = array_merge($defaults, $vars);

$options = $vars['options'];
unset($vars['options']);

$value = $vars['value'];
unset($vars['value']);

foreach ($options as $label => $option) {
	
	$vars['checked'] = strtolower($option) != strtolower($vars['value']);
	$vars['value'] = $option;
	
	$attributes = elgg_format_attributes($vars);
	
	// handle indexed array where label is not specified
	// @todo deprecate in Elgg 1.8
	if (is_integer($label)) {
		$label = $option;
	}
	
	echo "<label><input type=\"radio\" $attributes />$label</label><br />";
}