-
Notifications
You must be signed in to change notification settings - Fork 0
/
form_helper.html
266 lines (239 loc) · 8.42 KB
/
form_helper.html
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<!DOCTYPE html>
<html lang="en">
<head>
<title>Menukaarten-docs</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="assets/css/stylesheet.css" media="screen,print">
<link rel="stylesheet" href="assets/css/print.css" media="print">
<link rel="stylesheet" type="text/css" href="assets/css/shCore.css" media="screen,print">
<link rel="stylesheet" type="text/css" href="assets/css/shThemeDefault.css" media="screen,print">
<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/SyntaxHighlighter.js"></script>
<script type="text/javascript" src="assets/js/build_menu.js"></script>
</head>
<body>
<div id="header-wrapper">
<div id="header">
<h1>Documentation SexyFramework</h1>
<span>Created by Vincent Bremer & Douwe de Haan</span>
</div>
</div>
<div id="container">
<div id="menu-wrapper">
<div id="menu">
<h1>Table of contents</h1>
<ul></ul>
</div>
</div>
<div id="content-wrapper">
<div id="content">
<!-- START CONTENT -->
<h1>Form helper</h1>
<p>The form helper contains functions to help you easily build HTML forms. It can create textfields, selects, checkboxes, textareas and others. Below are a few examples of each available function and the resulting HTML.</p>
<h2>Opening a form</h2>
To create a form element you can use the following function:
<pre class="brush: php">
form::open($action, $attributes);
</pre>
<span class="bold">Parameters:</span>
<ul class="list">
<li>$action <span class="small">string optional</span></li>
<li>$attributes <span class="small">array optional</span></li>
</ul>
Opening a form with the method post:<br>
<pre class="brush: php">
echo form::open();
// Will return:
<form action="http://website.com/users/new" method="post">
</pre>
Opening a form with the method get:
<pre class="brush: php">
echo form::open('get');
// Will return:
<form action="http://website.com/users/new" method="get">
</pre>
Opening a form multipart form:
<pre class="brush: php">
echo form::open('post', array('enctype' => 'multipart/form-data'));
// Will return:
<form action="http://website.com/users/new" method="post" enctype="multipart/form-data">
</pre>
<h2>Closing a form</h2>
The form is closed with the close function, this function doesn't accept any arguments.
<pre class="brush: php">
echo form::close();
// Will return:
</form>
</pre>
<h2>Textfield</h2>
To create an input field with the type text, you can use the following function:
<pre class="brush: php">
form::textfield($name, $values, $attributes);
</pre>
<span class="bold">Parameters:</span>
<ul class="list">
<li>$name <span class="small">string</span> <span class="small red">required</span></li>
<li>$values <span class="small">string optional</span></li>
<li>$attributes <span class="small">array optional</span></li>
</ul>
Example 1:
<pre class="brush: php">
echo form::textfield('username', 'John doe'));
// Will return:
<input type="text" name="username" value="John Doe" id="id_username" size="30" />
</pre>
Example 2:
<pre class="brush: php">
echo form::textfield('age', '43', array('size' => 4, 'class' => 'input'));
// Will return:
<input type="text" name="username" value="John Doe" id="id_username" size="4" class="submit" />
</pre>
<h2>E-mail</h2>
The e-mail function is exactly the same as the textfield function, they share the same properties and parameters. Only the type is set to email. See <a href="#textfield">textfield</a> for the syntax.
<pre class="brush: php">
form::email($name, $values, $attributes);
</pre>
<h2>Password</h2>
The password function is also exactly the same as the textfield function, they share the same properties and parameters. Only the type is set to password. See <a href="#textfield">textfield</a> for the syntax.
<pre class="brush: php">
form::password($name, $values, $attributes);
</pre>
<h2>Label</h2>
<pre class="brush: php">
form::label($for, $name, $attributes);
</pre>
<span class="bold">Parameters:</span>
<ul class="list">
<li>$for <span class="small">string</span> <span class="small red">required</span></li>
<li>$name <span class="small">string</span> <span class="small red">required</span></li>
<li>$attributes <span class="small">array optional</span></li>
</ul>
Example 1:
<pre class="brush: php">
echo form::label('username', 'Username:'));
// Will return:
<label for="id_username">Username:</label>
</pre>
<h2>Select options</h2>
<pre class="brush: php">
form::select($name, $options, $selected, $attributes);
</pre>
<span class="bold">Parameters:</span>
<ul class="list">
<li>$name <span class="small">string</span> <span class="small red">required</span></li>
<li>$options <span class="small">array <span class="small red">required</span></span></li>
<li>$selected <span class="small">string optional</span></li>
<li>$attributes <span class="small">array optional</span></li>
</ul>
Example 1:
<pre class="brush: php">
$options = array(
'21' => 'John Doe',
'49' => 'Harry Smith',
'80' => 'Bill Williams'
);
echo form::select('user', $options, '49');
// Will return:
<select name="user">
<option value="21">John Doe</option>
<option value="49" selected="selected">Harry Smith</option>
<option value="80">Bill Williams</option>
</select>
</pre>
<h2>Radio buttons</h2>
To create an input field with the type text, you can use the following function:
<pre class="brush: php">
form::radio($name, $options, $checked, $attributes);
</pre>
<span class="bold">Parameters:</span>
<ul class="list">
<li>$name <span class="small">string</span> <span class="small red">required</span></li>
<li>$options <span class="small">array <span class="small red">required</span></span></li>
<li>$checked <span class="small">string optional</span></li>
<li>$attributes <span class="small">array optional</span></li>
</ul>
Example 1:
<pre class="brush: php">
$options = array(
1 => 'Yes',
0 => 'No'
);
echo form::radio('active', $options, 1);
// Will return:
<label class="wrap_label">
<input type="radio" name="active" value="1" checked="checked"> Yes
</label>
<label class="wrap_label">
<input type="radio" name="active" value="0"> No
</label>
</pre>
<h2>Textarea</h2>
For creating a textarea the following function can be used.
<pre class="brush: php">
form::textarea($name, $value, $attributes);
</pre>
<span class="bold">Parameters:</span>
<ul class="list">
<li>$name <span class="small">string</span> <span class="small red">required</span></li>
<li>$value <span class="small">string</span> <span class="small red">required</span></li>
<li>$attributes <span class="small">array optional</span></li>
</ul>
Example:
<pre class="brush: php">
echo form::textarea('description', 'Lorem ipsum dolar sit amet');
// Will return:
<textarea name="description" id="id_description">Lorem ipsum dolar sit amet</textarea>
</pre>
<h2>File upload</h2>
<pre class="brush: php">
form::file($name, $attributes);
</pre>
<span class="bold">Parameters:</span>
<ul class="list">
<li>$name <span class="small">string</span> <span class="small red">required</span></li>
<li>$attributes <span class="small">array optional</span></li>
</ul>
Example:
<pre class="brush: php">
echo form::file('image');
// Will return:
<input type="file" name="image" />
</pre>
<h2>Hidden field</h2>
<pre class="brush: php">
form::hidden($name, $value, $attributes);
</pre>
<span class="bold">Parameters:</span>
<ul class="list">
<li>$name <span class="small">string</span> <span class="small red">required</span></li>
<li>$value <span class="small">string</span> <span class="small red">required</span></li>
<li>$attributes <span class="small">array optional</span></li>
</ul>
Example:
<pre class="brush: php">
echo form::hidden('user_id', '542');
// Will return:
<input type="hidden" name="user_id" value="542" />
</pre>
<h2>Submit button</h2>
<pre class="brush: php">
form::textarea($name, $attributes);
</pre>
<span class="bold">Parameters:</span>
<ul class="list">
<li>$name <span class="small">string</span> <span class="small red">required</span></li>
<li>$attributes <span class="small">array optional</span></li>
</ul>
Example:
<pre class="brush: php">
echo form::submit('Save user');
// Will return:
<input type="submit" value="Save user" />
</pre>
<!-- END CONTENT -->
</div>
</div>
</div>
<script type="text/javascript" src="assets/js/SyntaxHighlighter_settings.js"></script>
</body>
</html>