dropdown.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * Elgg dropdown input
  4. * Displays a dropdown input field
  5. *
  6. * @uses $vars['value'] The current value, if any
  7. * @uses $vars['name'] The name of the input field
  8. * @uses $vars['options'] An array of strings representing the options for the dropdown field
  9. * @uses $vars['options_values'] An associative array of "value" => "option" where "value" is an internal name and "option" is
  10. * the value displayed on the button. Replaces $vars['options'] when defined.
  11. */
  12. $class = "elgg-input-dropdown";
  13. ?>
  14. <select name="<?php echo $vars['name']; ?>" class="<?php echo $class; ?>">
  15. <?php
  16. if (isset($vars['options_values'])) {
  17. foreach ($vars['options_values'] as $value => $option) {
  18. if ($value != $vars['value']) {
  19. echo "<option value=\"$value\">{$option}</option>";
  20. } else {
  21. echo "<option value=\"$value\" selected=\"selected\">{$option}</option>";
  22. }
  23. }
  24. } else {
  25. foreach ($vars['options'] as $option) {
  26. if ($option != $vars['value']) {
  27. echo "<option>{$option}</option>";
  28. } else {
  29. echo "<option selected=\"selected\">{$option}</option>";
  30. }
  31. }
  32. }
  33. ?>
  34. </select>