1 <?php
2
3 4 5 6 7
8
9 namespace nk2580\wordsmith\Inputs\Fields;
10
11 use nk2580\wordsmith\Inputs\Input as Input;
12
13 14 15 16 17
18 class SelectBoxField extends Input {
19
20 protected $options;
21
22 public function __construct($name, $options, $label = '', $value = '', $class = '', $readonly = false) {
23 parent::__construct($name, $label, $value, $class, $readonly);
24 $this->options = $options;
25 }
26
27 public function printField() {
28 $class = $this->getClassString();
29 echo '<label for="' . $this->name . '" >'.$this->label.' ';
30 echo '<select class="' . $class . '" name="' . $this->name . '" id="' . $this->name . '">';
31 foreach ($this->options as $label => $value) {
32 if ($this->value == $value) {
33 echo '<option selected="selected" value="'.$value.'">'.$label.'</option>';
34 } else {
35 echo '<option value="'.$value.'">'.$label.'</option>';
36 }
37 }
38 echo '</select></label>';
39 echo '<br/>';
40 }
41
42 public function isFieldValid() {
43 return true;
44 }
45
46 public function sanitize() {
47 return $this->value;
48 }
49
50 }
51