| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Create a text input field |
|---|
| 4 | * |
|---|
| 5 | * @package Elgg |
|---|
| 6 | * @subpackage Core |
|---|
| 7 | * @author Curverider Ltd |
|---|
| 8 | * @link http://elgg.org/ |
|---|
| 9 | * |
|---|
| 10 | * @uses $vars['value'] The current value, if any |
|---|
| 11 | * @uses $vars['internalname'] The name of the input field |
|---|
| 12 | * @uses $vars['internalid'] The id of the input field |
|---|
| 13 | * |
|---|
| 14 | * All other input attributes can be specified using their attribute name |
|---|
| 15 | * including event attributes such as onclick. |
|---|
| 16 | */ |
|---|
| 17 | |
|---|
| 18 | // remove all the junk that elgg_view throws into $vars |
|---|
| 19 | unset($vars['config']); |
|---|
| 20 | unset($vars['url']); |
|---|
| 21 | unset($vars['page_owner']); |
|---|
| 22 | unset($vars['page_owner_user']); |
|---|
| 23 | foreach ($_SESSION as $key=>$value) { |
|---|
| 24 | unset($vars[$key]); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | // backwards compatibility code |
|---|
| 29 | if (isset($vars['internalname'])) { |
|---|
| 30 | $vars['name'] = $vars['internalname']; |
|---|
| 31 | unset($vars['internalname']); |
|---|
| 32 | } |
|---|
| 33 | if (isset($vars['internalid'])) { |
|---|
| 34 | $vars['id'] = $vars['internalid']; |
|---|
| 35 | unset($vars['internalid']); |
|---|
| 36 | } |
|---|
| 37 | if (isset($vars['disabled'])) { |
|---|
| 38 | if ($vars['disabled']) { |
|---|
| 39 | $vars['disabled'] = 'disabled'; |
|---|
| 40 | } else { |
|---|
| 41 | unset($vars['disabled']); |
|---|
| 42 | } |
|---|
| 43 | } |
|---|
| 44 | $js = ''; |
|---|
| 45 | if (isset($vars['js'])) { |
|---|
| 46 | $js = $vars['js']; |
|---|
| 47 | unset($vars['js']); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | // default attributes |
|---|
| 51 | $attributes = array('type' => 'text', |
|---|
| 52 | 'value' => '', |
|---|
| 53 | 'class' => 'input-text', |
|---|
| 54 | ); |
|---|
| 55 | |
|---|
| 56 | $attributes = array_merge($attributes, $vars); |
|---|
| 57 | |
|---|
| 58 | $attributes['value'] = htmlspecialchars($attributes['value'], ENT_QUOTES, 'UTF-8'); |
|---|
| 59 | |
|---|
| 60 | echo "<input "; |
|---|
| 61 | foreach ($attributes as $k=>$v) { |
|---|
| 62 | echo "$k=\"$v\" "; |
|---|
| 63 | } |
|---|
| 64 | echo $js; |
|---|
| 65 | echo " />"; |
|---|