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 RadioButtonField 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 foreach ($this->options as $label => $value) {
30 if ($this->value == $value) {
31 echo '<label for="'.$this->name.$value.'"><input type="radio" checked="checked" name="'.$this->name.'" class="'.$class.'" id="'.$this->name.$value.'" value="'.$value.'"/> '.$label.'</label>';
32 } else {
33 echo '<label for="'.$this->name.$value.'"><input type="radio" name="'.$this->name.'" class="'.$class.'" id="'.$this->name.$value.'" value="'.$value.'"/> '.$label.'</label>';
34 }
35 echo '<br/>';
36 }
37 }
38
39 public function isFieldValid() {
40 return true;
41 }
42
43 public function sanitize() {
44 return ($this->value);
45 }
46
47 }
48
49 ?>