-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClipeHtml.php
More file actions
136 lines (118 loc) · 4.23 KB
/
ClipeHtml.php
File metadata and controls
136 lines (118 loc) · 4.23 KB
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
132
133
134
135
136
<?php
class ClipeHtml {
public function create($name, $options = array()) {
$defaultOptions = array(
'type' => 'text',
'class' => '',
'value' => null, //se le da prioridad a la variable POST
'div_class' => '',
'options' => array(),
'function_options' => null,
'options_empty' => false, //echo empty options
'multiple' => false,
'required' => false,
'label' => true,
'label_text' => 'Default',
'label_id' => false,
'readonly'=> false
);
if (isset($_POST[$name])) { //priority post value
$options['value'] = $_POST[$name];
}
$mergeOptions = array_replace_recursive($defaultOptions, $options);
echo '<div class="' . $mergeOptions['div_class'] . '">';
if ($mergeOptions['label']) {
$htmlLabelId = ($mergeOptions['label_id'])? 'id="' . $mergeOptions['label_id'] . '"' : '';
echo '<label ' . $htmlLabelId . ($mergeOptions['required'] ? 'class="required"' : '') . ' for="' . $name . '">' . __($mergeOptions['label_text'], 'clipe') . '</label>';
}
switch ($mergeOptions['type']) {
case 'text':
$this->printText($name, $mergeOptions);
break;
case 'textarea':
$this->printTextarea($name, $mergeOptions);
break;
case 'select':
$this->printSelect($name, $mergeOptions);
break;
case 'checkbox':
$this->printCheckbox($name, $mergeOptions);
break;
case 'password':
$this->printPassword($name, $mergeOptions);
break;
default:
break;
}
echo '</div>';
}
private function printText($name, $options) {
?>
<input class="<?php echo $options['class']; ?>" name="<?php echo $name; ?>"
id="<?php echo $name; ?>" value="<?php echo $options['value']; ?>" <?php echo $options['required'] ? 'required' : ''; ?>
<?php echo $options['readonly'] ? 'readonly' : ''; ?>>
<?php
}
private function printPassword($name, $options) {
?>
<input type="password" class="<?php echo $options['class']; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="" <?php echo $options['required'] ? 'required' : ''; ?>>
<?php
}
private function printTextarea($name, $options) {
?>
<textarea class="<?php echo $options['class']; ?>" name="<?php echo $name; ?>" id="<?php echo $name; ?>"
<?php echo $options['required'] ? 'required' : ''; ?> <?php echo $options['readonly'] ? 'readonly' : ''; ?> ><?php echo $options['value']; ?></textarea>
<?php
}
private function printSelect($name, $options) {
?>
<select class="<?php echo $options['class']; ?>" name="<?php echo $name; ?><?php echo $options['multiple'] ? '[]' : ''; ?>" id="<?php echo $name; ?>" <?php echo $options['multiple'] ? 'multiple' : ''; ?> <?php echo $options['required'] ? 'required' : ''; ?>>
<?php
if ($options['options_empty']) {
?><option value=""></option><?php
}
?>
<?php
if (!empty($options['options'])) {
foreach ($options['options'] as $key => $value) {
$selected = '';
if (isset($options['value'])) {
if (is_array($options['value'])) {
if (in_array($key, $options['value'])) {
$selected = 'selected';
}
} elseif ($options['value'] == $key) {
$selected = 'selected';
}
}
?> <option <?php echo $selected; ?> value="<?php echo $key ?>" ><?php echo $value ?></option><?php
}
}
?>
</select>
<?php
}
private function printCheckbox($name, $options) {
foreach ($options['options'] as $key => $value) {
$selected = '';
if (isset($options['value'])) {
if (is_array($options['value'])) {
if (in_array($key, $options['value'])) {
$selected = 'checked';
}
} elseif ($options['value'] == $key) {
$selected = 'checked';
}
}
?>
<div class="checkbox">
<label >
<input <?php echo $selected;?> type="checkbox" id="<?php echo $name; ?>" name="<?php echo $name; ?>[]" value="<?php echo $key ?>"/>
<?php echo $value; ?>
</label>
</div>
<?php
}
}
}
?>