init
[garradin.git] / include / libs / template_lite / plugins / function.html_input.php
1 <?php
2 /**
3 * template_lite {html_input} function plugin
4 *
5 * Type: function
6 * Name: html_input
7 * Purpose: Creates an input text or password box
8 * Input:
9 * - name = the name of the textbox
10 * - password = boolean - if set, this box will be a password box
11 * - value = optional default value for the input box
12 * - size = optional size for the input box
13 * - length = optional maxlength for the input box
14 * Author: Paul Lockaby <paul@paullockaby.com>
15 */
16 function tpl_function_html_input($params, &$tpl)
17 {
18 require_once("shared.escape_chars.php");
19 $name = null;
20 $value = '';
21 $password = false;
22 $extra = '';
23
24 foreach($params as $_key => $_value)
25 {
26 switch($_key)
27 {
28 case 'name':
29 case 'value':
30 $$_key = $_value;
31 break;
32 case 'password':
33 $$_key = true;
34 break;
35 default:
36 if(!is_array($_key))
37 {
38 $extra .= ' ' . $_key . '="' . tpl_escape_chars($_value) . '"';
39 }
40 else
41 {
42 throw new Template_Exception("html_input: attribute '$_key' cannot be an array", $tpl);
43 }
44 }
45 }
46
47 if (!isset($name) || empty($name))
48 {
49 throw new Template_Exception("html_input: missing 'name' parameter", $tpl);
50 return;
51 }
52
53 $toReturn = '<input type="';
54 $toReturn .= $password ? 'password' : 'text';
55 $toReturn .= '" name="' . tpl_escape_chars($name) . '" value="' . tpl_escape_chars($value) . '" ' . $extra . ' />';
56 return $toReturn;
57 }
58 ?>