Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

developers/views/default/theme_sandbox/forms.php (1 issue)

1
<?php
2
$ipsum = elgg_view('developers/ipsum');
3
?><form action="#">
4
	<fieldset>
5
		<legend>Fieldset Legend</legend>
6
		<?php
7
		echo elgg_view_field([
8
			'#type' => 'text',
9
			'required' => true,
10
			'name' => 'f1',
11
			'id' => 'f1',
12
			'value' => 'input text',
13
			'#label' => 'Text input (.elgg-input-text):',
14
			'#help' => 'This is how help text looks',
15
		]);
16
17
		echo elgg_view_field([
18
			'#type' => 'password',
19
			'name' => 'f2',
20
			'id' => 'f2',
21
			'value' => 'password',
22
			'#label' => 'Password input (.elgg-input-password):',
23
		]);
24
25
		echo elgg_view_field([
26
			'#type' => 'radio',
27
			'name' => 'f3',
28
			'id' => 'f3',
29
			'options' => [
30
				'a (.elgg-input-radio)' => 1,
31
				'b (.elgg-input-radio)' => 2
32
			],
33
			'value' => 2,
34
			'#label' => 'Radio input (.elgg-input-radios):',
35
		]);
36
37
		echo elgg_view_field([
38
			'#type' => 'radio',
39
			'name' => 'f3a',
40
			'id' => 'f3a',
41
			'options_values' => [
42
				'a' => 'a (.elgg-input-radio)',
43
				'b' => 'b (.elgg-input-radio)',
44
				[
45
					'text' => 'c (.elgg-input-radio) from array',
46
					'value' => 'c',
47
					'title' => 'c (.elgg-input-radio) from array',
48
				],
49
			],
50
			'value' => 'c',
51
			'#label' => 'Radio input (.elgg-input-radios) with options_values:',
52
		]);
53
54
		echo elgg_view_field([
55
			'#type' => 'checkbox',
56
			'name' => 'f4s',
57
			'id' => 'f4s',
58
			'value' => 1,
59
			'default' => false,
60
			'required' => true,
61
			'label' => 'a (.elgg-input-checkbox)',
62
			'#help' => 'Single checkbox .elgg-input-checkbox wrapped in .elgg-input-single-checkbox (only label)',
63
		]);
64
65
		echo elgg_view_field([
66
			'#type' => 'checkbox',
67
			'name' => 'f4s',
68
			'id' => 'f4s',
69
			'value' => 1,
70
			'default' => false,
71
			'required' => true,
72
			'#label' => 'a (.elgg-input-checkbox)',
73
			'#help' => 'Single checkbox .elgg-input-checkbox wrapped in .elgg-input-single-checkbox (only #label)',
74
		]);
75
		echo elgg_view_field([
76
			'#type' => 'checkbox',
77
			'name' => 'f4s1',
78
			'id' => 'f4s1',
79
			'value' => 1,
80
			'switch' => true,
81
			'default' => false,
82
			'required' => true,
83
			'#label' => 'a (.elgg-input-checkbox) with switch style',
84
			'#help' => 'Single checkbox .elgg-input-checkbox ',
85
		]);
86
87
		echo elgg_view_field([
88
			'#type' => 'checkbox',
89
			'name' => 'f4s2',
90
			'id' => 'f4s2',
91
			'value' => 1,
92
			'default' => false,
93
			'required' => true,
94
			'#label' => 'a (.elgg-input-checkbox) - Field label',
95
			'label' => 'a (.elgg-input-checkbox) - Input label',
96
			'#help' => 'Single checkbox .elgg-input-checkbox wrapped in .elgg-input-single-checkbox (label and #label)',
97
		]);
98
		
99
		echo elgg_view_input('checkbox', [
1 ignored issue
show
Deprecated Code introduced by Ismayil Khayredinov
The function elgg_view_input() has been deprecated: 2.3 Use elgg_view_field() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

99
		echo /** @scrutinizer ignore-deprecated */ elgg_view_input('checkbox', [

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
100
			'name' => 'f4s3',
101
			'id' => 'f4s3',
102
			'value' => 1,
103
			'default' => false,
104
			'required' => true,
105
			'label' => 'a (.elgg-input-checkbox)',
106
			'help' => 'Single checkbox .elgg-input-checkbox wrapped in .elgg-input-single-checkbox using elgg_view_input',
107
		]);
108
		
109
		echo elgg_view_field([
110
			'#type' => 'checkboxes',
111
			'name' => 'f4',
112
			'id' => 'f4',
113
			'options' => [
114
				'a (.elgg-input-checkbox)' => 1,
115
				'b (.elgg-input-checkbox)' => 2
116
			],
117
			'value' => 2,
118
			'#label' => 'Checkboxes input (.elgg-input-checkboxes):',
119
		]);
120
121
		echo elgg_view_field([
122
			'#type' => 'checkboxes',
123
			'name' => 'f4a',
124
			'id' => 'f4a',
125
			'switch' => true,
126
			'options' => [
127
				'a (.elgg-input-checkbox)' => 1,
128
				'b (.elgg-input-checkbox)' => 2
129
			],
130
			'#label' => 'Checkboxes input (.elgg-input-checkboxes) with switch style:',
131
		]);
132
133
		echo elgg_view_field([
134
			'#type' => 'checkboxes',
135
			'name' => 'f4b',
136
			'id' => 'f4b',
137
			'options_values' => [
138
				'a' => 'a (.elgg-input-checkbox)',
139
				'b' => 'b (.elgg-input-checkbox)',
140
				[
141
					'text' => 'c (.elgg-input-checkbox) from array',
142
					'value' => 'c',
143
					'title' => 'c (.elgg-input-checkbox) from array',
144
				],
145
			],
146
			'value' => ['a', 'c'],
147
			'#label' => 'Checkboxes input (.elgg-input-checkboxes) with options_values:',
148
		]);
149
150
		echo elgg_view_field([
151
			'#type' => 'select',
152
			'name' => 'f5',
153
			'id' => 'f5',
154
			'options' => [
155
				'option 1',
156
				'option 2',
157
				[
158
					'text' => 'disabled',
159
					'disabled' => true,
160
				],
161
			],
162
			'value' => 'option 2',
163
			'#label' => 'Select input (dropdown) (.elgg-input-select) with a disabled option:',
164
		]);
165
166
		echo elgg_view_field([
167
			'#type' => 'select',
168
			'name' => 'f50',
169
			'id' => 'f50',
170
			'options' => [
171
				'option 1',
172
				[
173
					'label' => 'optgroup label',
174
					'options' => [
175
						'value 1a' => 'option 1a',
176
						'value 1b' => 'option 1b',
177
						[
178
							'text' => 'option 1c',
179
							'value' => 'value 1c',
180
						]
181
					]
182
				],
183
				'option 2',
184
				[
185
					'text' => 'disabled',
186
					'disabled' => true,
187
				],
188
			],
189
			'#label' => 'Select input (dropdown) (.elgg-input-select) with an optgroup:',
190
		]);
191
192
		echo elgg_view_field([
193
			'#type' => 'select',
194
			'name' => 'f51[]',
195
			'id' => 'f51',
196
			'options_values' => [
197
				'value 1' => 'option 1',
198
				'value 2' => 'option 2',
199
				'value 3' => [
200
					'text' => 'option 3',
201
				],
202
				'value 4' => 'option 4',
203
			],
204
			'multiple' => true,
205
			'#label' => 'Select input (multiselect) (.elgg-input-select):',
206
		]);
207
208
		echo elgg_view_field([
209
			'#type' => 'select',
210
			'name' => 'f52[]',
211
			'id' => 'f52',
212
			'options_values' => [
213
				'value 1' => 'option 1',
214
				'value 2' => 'option 2',
215
				'value 3' => [
216
					'text' => 'option 3',
217
				],
218
				'value 4' => 'option 4',
219
			],
220
			'multiple' => true,
221
			'value' => ['value 1', 'value 3'],
222
			'#label' => 'Select input (multiselect) (.elgg-input-select) with options_values and multiple values selected:',
223
		]);
224
225
		echo elgg_view_field([
226
			'#type' => 'select',
227
			'name' => 'f521[]',
228
			'id' => 'f521',
229
			'options' => [
230
				'option 1',
231
				'option 2',
232
				'option 3',
233
				'option 4',
234
			],
235
			'multiple' => true,
236
			'value' => ['option 1', 'option 3'],
237
			'#label' => 'Select input (multiselect) (.elgg-input-select) with options and multiple values selected:',
238
		]);
239
240
		echo elgg_view_field([
241
			'#type' => 'select',
242
			'name' => 'f53[]',
243
			'id' => 'f53',
244
			'options_values' => [
245
				'value 1' => 'option 1',
246
				'value 2' => 'option 2',
247
				'value 3' => [
248
					'text' => 'option 3',
249
				],
250
				[
251
					'label' => 'optgroup label',
252
					'options' => [
253
						'value 1a' => 'option 1a',
254
						'value 1b' => 'option 1b',
255
						[
256
							'text' => 'option 1c',
257
							'value' => 'value 1c',
258
						]
259
					]
260
				],
261
				'value 4' => 'option 4',
262
			],
263
			'multiple' => true,
264
			'#label' => 'Select input (multiselect) with optgroup (.elgg-input-select):',
265
		]);
266
267
		echo elgg_view_field([
268
			'#type' => 'access',
269
			'name' => 'f6',
270
			'id' => 'f6',
271
			'value' => ACCESS_PUBLIC,
272
			'#label' => 'Access input (.elgg-input-access):',
273
		]);
274
275
		echo elgg_view_field([
276
			'#type' => 'file',
277
			'name' => 'f7',
278
			'id' => 'f7',
279
			'#label' => 'File input (.elgg-input-file):',
280
		]);
281
282
		echo elgg_view_field([
283
			'#type' => 'url',
284
			'name' => 'f8',
285
			'id' => 'f8',
286
			'value' => 'http://elgg.org/',
287
			'#label' => 'URL input (.elgg-input-url):',
288
		]);
289
290
		echo elgg_view_field([
291
			'#type' => 'tags',
292
			'name' => 'f9',
293
			'id' => 'f9',
294
			'value' => 'one, two, three',
295
			'#label' => 'Tags input (.elgg-input-tags):',
296
		]);
297
298
		echo elgg_view_field([
299
			'#type' => 'email',
300
			'name' => 'f10',
301
			'id' => 'f10',
302
			'value' => '[email protected]',
303
			'#label' => 'Email input (.elgg-input-email):',
304
		]);
305
306
		echo elgg_view_field([
307
			'#type' => 'autocomplete',
308
			'name' => 'f11a',
309
			'id' => 'f11a',
310
			'match_on' => 'groups',
311
			'#label' => 'Groups autocomplete input (.elgg-input-autocomplete):',
312
		]);
313
314
		echo elgg_view_field([
315
			'#type' => 'autocomplete',
316
			'name' => 'f11b',
317
			'id' => 'f11b',
318
			'match_on' => 'users',
319
			'#label' => 'Users autocomplete input (.elgg-input-autocomplete):',
320
		]);
321
322
		echo elgg_view_field([
323
			'#type' => 'date',
324
			'name' => 'f12',
325
			'id' => 'f12',
326
			'value' => '2012-12-31',
327
			'#label' => 'Date input (.elgg-input-date):',
328
		]);
329
330
		$year = date('Y');
331
		echo elgg_view_field([
332
			'#type' => 'date',
333
			'name' => 'f12-custom',
334
			'id' => 'f12-custom',
335
			'value' => "$year/02/01",
336
			'timestamp' => true,
337
			'datepicker_options' => [
338
				'dateFormat' => 'yy/mm/dd',
339
				'changeMonth' => false,
340
				'changeYear' => false,
341
				'minDate' => "$year/01/15",
342
				'maxDate' => "$year/02/15",
343
			],
344
			'#label' => 'Date input (.elgg-input-date) with custom options:',
345
			'#help' => 'Select a date from 15 Jan to 15 Feb',
346
		]);
347
348
		echo elgg_view_field([
349
			'#type' => 'userpicker',
350
			'name' => 'f13',
351
			'id' => 'f13',
352
			'#label' => 'User picker input (.elgg-user-picker):',
353
		]);
354
355
		echo elgg_view_field([
356
			'#type' => 'userpicker',
357
			'name' => 'f16',
358
			'id' => 'f16',
359
			'limit' => 1,
360
			'#label' => 'User picker input (with max 1 results) (.elgg-user-picker):',
361
		]);
362
363
		echo elgg_view_field([
364
			'#type' => 'plaintext',
365
			'name' => 'f15',
366
			'id' => 'f15',
367
			'value' => $ipsum,
368
			'#label' => 'Plain textarea input (.elgg-input-plaintext):',
369
		]);
370
371
		echo elgg_view_field([
372
			'#type' => 'longtext',
373
			'name' => 'f14',
374
			'id' => 'f14',
375
			'value' => $ipsum,
376
			'#label' => 'Long textarea input (.elgg-input-longtext):',
377
		]);
378
379
		echo elgg_view_field([
380
			'#type' => 'longtext',
381
			'name' => 'f14a',
382
			'id' => 'f14a',
383
			'value' => $ipsum,
384
			'editor' => false,
385
			'#label' => 'Long textarea input (.elgg-input-longtext) with a disabled editor:',
386
		]);
387
388
		echo elgg_view_field([
389
			'#type' => 'longtext',
390
			'name' => 'f14b',
391
			'id' => 'f14b',
392
			'value' => $ipsum,
393
			'visual' => false,
394
			'#label' => 'Long textarea input (.elgg-input-longtext) without a visual editor activated by default:',
395
		]);
396
397
		echo elgg_view_field([
398
			'#type' => 'longtext',
399
			'name' => 'f14c',
400
			'id' => 'f14c',
401
			'value' => $ipsum,
402
			'editor_type' => 'simple',
403
			'#label' => 'Long textarea input (.elgg-input-longtext) with the editor_type configured as "simple":',
404
		]);
405
406
		echo elgg_view_field([
407
			'#type' => 'number',
408
			'name' => 'f15',
409
			'id' => 'f15',
410
			'value' => 1,
411
			'min' => 1,
412
			'step' => 1,
413
			'#label' => 'Number input (.elgg-input-number) with custom options:',
414
			'#help' => 'Enter an integer number larger than zero',
415
		]);
416
417
		$dt = new \DateTime(null, new \DateTimeZone('UTC'));
418
		$hour_options = [];
419
		$hour_options_ts = range(0, 24 * 60 * 60, 900); // step of 15 minutes
420
		foreach ($hour_options_ts as $ts) {
421
			$hour_options[$ts] = $dt->setTimestamp($ts)->format('g:ia');
422
		}
423
424
		echo elgg_view_field([
425
			'#type' => 'fieldset',
426
			'name' => 'f16',
427
			'legend' => 'Fieldset with a legend',
428
			'fields' => [
429
					[
430
					'#type' => 'text',
431
					'#label' => 'Text field',
432
					'required' => true,
433
					],
434
					[
435
					'#type' => 'fieldset',
436
					'#label' => 'Date and time fieldset',
437
					'align' => 'horizontal',
438
					'fields' => [
439
							[
440
							'#type' => 'date',
441
							'value' => time(),
442
							'timestamp' => true,
443
							'#label' => 'Date',
444
							],
445
							[
446
							'#type' => 'select',
447
							'#label' => 'Time',
448
							'options' => $hour_options,
449
							],
450
					],
451
					],
452
					[
453
					'#type' => 'fieldset',
454
					'#label' => 'Nested fieldset',
455
					'#help' => 'Fieldset with horizontal alignment of fields',
456
					'align' => 'horizontal',
457
					'fields' => [
458
						[
459
							'#type' => 'button',
460
							'type' => 'submit',
461
							'text' => 'Save',
462
							'icon' => 'save',
463
						],
464
							[
465
							'#type' => 'button',
466
							'text' => 'Download',
467
							'icon' => 'download',
468
							'class' => 'elgg-button-action',
469
							],
470
							[
471
							'#type' => 'button',
472
							'type' => 'reset',
473
							'text' => 'Cancel',
474
							'icon' => 'remove',
475
							],
476
					],
477
					],
478
			]
479
		]);
480
		?>
481
	</fieldset>
482
</form>
483