aboutsummaryrefslogtreecommitdiff
path: root/views/default/input/default.php
blob: 59ad357e78e75e712049f8a8413dc05c2a49bf8d (plain)
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
<?php
/**
 * Create an input field
 *
 * @package Elgg
 * @subpackage Core
 * @author Curverider Ltd
 * @link http://elgg.org/
 *
 * @uses $vars['internalname'] The name of the input field
 * @uses $vars['internalid'] The id of the input field
 * @deprecated $vars['js'] Use named attributes instead
 *
 * All other input attributes can be specified using their attribute name
 * including javascript event attributes such as onclick.
 */

// remove all the junk that elgg_view throws into $vars

unset($vars['config']);
unset($vars['url']);
unset($vars['page_owner']);
unset($vars['page_owner_user']);
foreach ($_SESSION as $key=>$value) {
	unset($vars[$key]);
}

// backwards compatibility code
if (isset($vars['internalname'])) {
	$vars['name'] = $vars['internalname'];
	unset($vars['internalname']);
}

if (isset($vars['internalid'])) {
	$vars['id'] = $vars['internalid'];
	unset($vars['internalid']);
}

$js = '';
if (isset($vars['js'])) {
	$js = $vars['js'];
	unset($vars['js']);
}

// default attributes
$defaults = array(
	'type' => 'text',
	'value'	=> '',
);

$attributes = array_merge($defaults, $vars);

$attributes['value'] = htmlspecialchars($attributes['value'], ENT_QUOTES, 'UTF-8');


//Build the input
$element = array();

$element[] = "<input";
foreach ($attributes as $attr => $val) {
	if ($val === TRUE) {
		$element[] = $attr;
	} elseif ($val !== FALSE) {
		$val = addslashes($val);
		$element[] = "$attr=\"$val\"";
	}
}
$element[] = $js;
$element[] = "/>";

echo implode(" ", $tag);