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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
<?php
/*
** $Id$
**
** ITools - the Internet Tools Library
**
** Copyright (C) 1995-2003 by the ITools Authors.
** This program is free software; you can redistribute it and/or
** modify it under the terms of either the GNU General Public License
** or the GNU Lesser General Public License, as published by the Free
** Software Foundation. See http://www.gnu.org/licenses/ for details.
**
** class it_html_form - Generic HTML Form
*/
/**
* Functions to facilitate creation of HTML forms
*/
class it_html_form
{
var $name; /* Name of form */
/**
* Constructor: set action, name and method (echo <FORM> tag)
* @param $action the action to be performed by this form or empty for link to self
* @param $name form name (optional)
* @param $method the method used for the action (defaults to 'post')
* @param $target Target frame of the form (optional)
*/
function it_html_form($action='*', $name='', $method='post', $target='')
{
if ($action == '*')
$action = $_SERVER['PHP_SELF'];
$this->name = $name;
echo '<form method="'.$method.'" action="'.$action.'"';
if ($target)
echo " target=\"$target\"";
if ($name)
echo " name=\"$name\"";
echo '>';
}
/**
* Close the form (echo </FORM> tag)
*/
function close()
{
echo "</form>";
}
/**
* Add a parameter (as a hidden field)
* @param $name parameter name
* @param $value default (?) value
* @param $return_output if true, output will be returned instaed of echoed
*/
function hidden($name, $value="", $return_output=false)
{
$output = "<input type=\"hidden\" name=\"$name\" value=\"" . htmlspecialchars($value) . "\">";
if ($return_output)
return $output;
else
echo $output;
}
/**
* Create a text field or a textarea if size is width:height
* @param $name text field name
* @param $size textfield width[:height] in chars
* @param $maxlength maximum length of input
* @param $value text field value
*/
function text($name, $size=8, $maxlength=255, $value="")
{
if (strchr($size, ":"))
{
list($cols, $rows) = explode(":", $size);
echo "<textarea name=\"$name\" rows=\"$rows\" cols=\"$cols\">".htmlspecialchars($value)."</textarea>";
}
else
echo "<input type=\"text\" name=\"$name\" size=\"$size\" maxlength=\"$maxlength\" value=\"".htmlspecialchars($value)."\">";
}
/**
* Create a password field (masked characters)
* @param $name text field name
* @param $size textfield width[:height] in chars
* @param $maxlength maximum length of input
* @param $value text field value
*/
function password($name, $size=8, $maxlength=255, $value="")
{
echo "<input type=\"password\" name=\"$name\" size=\"$size\" maxlength=\"$maxlength\" value=\"".htmlspecialchars($value)."\">";
}
/**
* Create a dropdown menu object
* @param $name dropdown field name
* @param $options array (value => text) of available options or
* string key:val{,key:val} where key will be rawurldecoded so it may contain %2C as comma
* @param $selected currently selected value
*/
function select($name, $options, $selected='')
{
if (!is_array($options))
{
$opts = explode(',', $options);
$options = array();
foreach($opts as $opt)
{
list($key, $value) = explode(':', $opt);
$options[rawurldecode($key)] = $value;
}
}
echo '<select name="'.$name.'">';
foreach($options as $value => $text)
{
$sel = ($value == $selected) ? ' selected' : '';
echo '<option value="'.htmlspecialchars($value).'"'.$sel.'>'.$text.'</option>';
}
echo '</select>';
}
/**
* Create a filename field with browse button
* @param $name file field name
* @param $label label to be echoed before the field
* @param $size file field width in chars
* @param $maxlength maximum length of input
* @param $value text field value
*/
function file($name, $label="", $size=16, $maxlength=255, $value="filename")
{
echo $label."<input type=\"file\" name=\"$name\" size=\"$size\" maxlength=\"$maxlength\" value=\"".htmlspecialchars($value)."\">";
}
/**
* Create a Submit button
* @param $label button label
* @param $name button name
*/
function submit($label="", $name="")
{
if (!$label)
$label = T('Button-Save');
echo "<input type=\"submit\" value=\"$label\"";
if ($name) echo " name=\"$name\"";
echo ">";
}
} /* End class html_form */
?>
|