Elgg  Version 1.9
select.php
Go to the documentation of this file.
1 <?php
21 if (isset($vars['class'])) {
22  $vars['class'] = "elgg-input-dropdown {$vars['class']}";
23 } else {
24  $vars['class'] = "elgg-input-dropdown";
25 }
26 
27 $defaults = array(
28  'disabled' => false,
29  'value' => '',
30  'options_values' => array(),
31  'options' => array(),
32 );
33 
34 $vars = array_merge($defaults, $vars);
35 
36 $options_values = $vars['options_values'];
37 unset($vars['options_values']);
38 
39 $options = $vars['options'];
40 unset($vars['options']);
41 
42 $value = is_array($vars['value']) ? $vars['value'] : array($vars['value']);
43 $value = array_map('strval', $value);
44 unset($vars['value']);
45 
46 $vars['multiple'] = !empty($vars['multiple']);
47 
48 // Add trailing [] to name if multiple is enabled to allow the form to send multiple values
49 if ($vars['multiple'] && !empty($vars['name']) && is_string($vars['name'])) {
50  if (substr($vars['name'], -2) != '[]') {
51  $vars['name'] = $vars['name'] . '[]';
52  }
53 }
54 
55 ?>
56 <select <?php echo elgg_format_attributes($vars); ?>>
57 <?php
58 
59 if ($options_values) {
60  foreach ($options_values as $opt_value => $option) {
61 
62  $option_attrs = elgg_format_attributes(array(
63  'value' => $opt_value,
64  'selected' => in_array((string)$opt_value, $value),
65  ));
66 
67  echo "<option $option_attrs>$option</option>";
68  }
69 } else {
70  if (is_array($options)) {
71  foreach ($options as $option) {
72 
73  $option_attrs = elgg_format_attributes(array(
74  'selected' => in_array((string)$option, $value)
75  ));
76 
77  echo "<option $option_attrs>$option</option>";
78  }
79  }
80 }
81 ?>
82 </select>
$defaults
Definition: select.php:27
$vars
Definition: select.php:34
$value
Definition: select.php:42
$options_values
Definition: select.php:36
$options
Definition: select.php:39
elgg echo
Translates a string.
Definition: languages.js:43
elgg_format_attributes(array $attrs=array())
Converts an associative array into a string of well-formed attributes.
Definition: output.php:118