-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form.Field.Radio.class.php
131 lines (115 loc) · 2.46 KB
/
Form.Field.Radio.class.php
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
require_once dirname(__FILE__) . "/Form.class.php";
/**
*
* FORM_RADIO
*
*
* An HTML radio
*
*/
class FORM_RADIO extends FORM_FIELD {
/**
* The radio's 'value' field
*
* @var string
*/
protected $text;
/**
* The radio's shared name
*
* @var string
*/
protected $radio_name;
/**
* Constructor
*
* @param FORM_FIELDSET $parent
* @param string $radio_name
* @param string $unique_name
* @param string $text
* @param string|array $labels
* @param bool $default_checked
*/
public function __construct(&$parent, $radio_name, $unique_name, $text, $labels=null, $default_checked=false) {
parent::__construct($parent, $unique_name, $labels);
$this->text = $text;
$this->radio_name = $radio_name;
$this->setDefaultChecked($default_checked);
}
/**
* Get the name of the radio list that this belongs to
*
* @return string
*/
public function getRadioName() {
return $this->radio_name;
}
/**
* Get the text
*
* @return string
*/
public function getText() {
return $this->text;
}
/**
* Is this radio checked?
*
* @return boolean
*/
public function isChecked() {
return $this->form()->getRadioCheckedText($this->getRadioName()) == $this->getText();
}
/**
* Is this radio checked by default?
*
* @return boolean
*/
public function isDefaultChecked() {
return $this->form()->getRadioDefaultCheckedText($this->getRadioName()) == $this->getText();
}
/**
* Is the posted radio checked?
*
* @return boolean
*/
public function isPostedChecked() {
return $this->form()->getRadioPostedCheckedText($this->getRadioName()) == $this->getText();
}
/**
* Set the radio checked by default
*
* @return FORM_RADIO
*/
public function setDefaultChecked() {
$this->form()->setRadioDefaultChecked($this->getRadioName(), $this->getText());
return $this;
}
/**
* Set the posted radio checked
*
* @return FORM_RADIO
*/
public function setPostedChecked() {
$this->form()->setRadioPostedChecked($this->getRadioName(), $this->getText());
return $this;
}
/**
* Render the radio element
*
* @param array $languages
* @return string
*/
public function fieldHTML(array $languages) {
$this->setFieldAttribute('value', $this->text);
if ($this->isChecked()) {
$this->setFieldAttribute('checked', 'checked');
}
$attributes = $this->getFieldAttributesString(array(
'type' => $this->type(),
'name' => $this->getRadioName(),
));
return "<input {$attributes} />";
}
}