|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Form element creation helpers |
|
5
|
|
|
* |
|
6
|
|
|
* PHP Version 5 |
|
7
|
|
|
* |
|
8
|
|
|
* @category Core |
|
9
|
|
|
* @package Template |
|
10
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
|
11
|
|
|
* @copyright 2013 cSphere Team |
|
12
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
|
13
|
|
|
* @link http://www.csphere.eu |
|
14
|
|
|
**/ |
|
15
|
|
|
|
|
16
|
|
|
namespace csphere\core\template; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Form element creation helpers |
|
20
|
|
|
* |
|
21
|
|
|
* @category Core |
|
22
|
|
|
* @package Template |
|
23
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
|
24
|
|
|
* @copyright 2013 cSphere Team |
|
25
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
|
26
|
|
|
* @link http://www.csphere.eu |
|
27
|
|
|
**/ |
|
28
|
|
|
|
|
29
|
|
|
abstract class Form |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* Creates the HTML option tags for a select tag |
|
33
|
|
|
* |
|
34
|
|
|
* @param array $data Data with value and text keys per row |
|
35
|
|
|
* @param string $value Name of the key to use for the option value |
|
36
|
|
|
* @param string $text Name of the key to use for the option text |
|
37
|
|
|
* @param string $default Default value that should be marked as selected |
|
38
|
|
|
* |
|
39
|
|
|
* @return string |
|
40
|
|
|
**/ |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
public static function options(array $data, $value, $text, $default = '') |
|
43
|
|
|
{ |
|
44
|
|
|
$result = ''; |
|
45
|
|
|
|
|
46
|
|
|
// Add all options with value and text |
|
47
|
|
|
foreach ($data AS $option) { |
|
48
|
|
|
|
|
49
|
|
|
// Check if value is default |
|
50
|
|
|
$active = ''; |
|
51
|
|
|
|
|
52
|
|
|
if ($option[$value] == $default) { |
|
53
|
|
|
|
|
54
|
|
|
$active = ' selected="selected"'; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
// HHVM does not support ENT_SUBSTITUTE and ENT_HTML5 yet |
|
58
|
|
|
$option[$value] = htmlspecialchars( |
|
59
|
|
|
$option[$value], ENT_QUOTES, 'UTF-8', false |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
$option[$text] = htmlspecialchars( |
|
63
|
|
|
$option[$text], ENT_QUOTES, 'UTF-8', false |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
// Build HTML string |
|
67
|
|
|
$result .= '<option value="' . $option[$value] . '"' . $active . '>' |
|
68
|
|
|
. $option[$text] |
|
69
|
|
|
. '</option>'; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $result; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|