forked from depage/depage-forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
htmlform.php
915 lines (839 loc) · 28.1 KB
/
htmlform.php
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
<?php
/**
* @file htmlform.php
* @brief htmlform class and autoloader
*
* @author Frank Hellenkamp <[email protected]>
* @author Sebastian Reinhold <[email protected]>
**/
// {{{ documentation
/**
* @mainpage
*
* @intro
* @image html icon_depage-forms.png
* @htmlinclude main-intro.html
* @endintro
*
* @section Usage
*
* depage-forms will mainly be used through the @link depage::htmlform::htmlform
* htmlform-class@endlink. It is the main interface through which you can add
* inputs, fieldsets and steps.
*
* You can find a list of available input-class in @link depage::htmlform::elements
* elements@endlink.
*
* @endsection
*
* @subpage developer
*
* @htmlinclude main-extended.html
**/
/**
* @page usage Usage
*
**/
/**
* @page developer Developer guide
*
* The idea behind this project is to combine comfortable form-generation and
* modern browser functionality with maximum client coverage.
*
* Comfort
* - We abstract browser specifics from HTML-forms to provide a clean interface
* to web developers. All configuration is located in one place.
*
* Coverage
* - To reach as many users as possible we have included several fallbacks for
* old browsers. Depage-forms mimics validation-behavior of modern browsers
* with JavaScript (client-side) or PHP (server-side).
*
* HTML5
* - We follow the HTML5 spec where it's sensible. The only clash so far is
* @link depage::htmlform::elements::multiple::htmlInputAttributes checkbox
* validation @endlink .
* - We aim to provide as much HTML5 functionality as possible.
*
* Customization
* - Input-elements can be easily modified by overriding the included
* element-classes.
* - New element-classes are automatically integrated by the autoloader. (They
* can be instantiated with @link depage::htmlform::abstracts::container::__call
* add @endlink (runtime generated methods))
*
* @section prerequisites Developer Prerequisites
*
* - PHP 5.3
* - PHPUnit 3.5 (to run included unit tests)
* - Doxygen 1.7.2 (to generate documentation)
*
* @section style Coding style
*
* Generally, follow Zend coding standard
*
* @section Deployment
*
* To generate a gzipped release of the library (includes examples):
*
* <pre>$ make release</pre>
*
* To generate a gzipped release with the essentials for working environments:
*
* <pre>$ make min</pre>
*
* @section Tests
*
* To run the unit tests:
*
* <pre>$ make test</pre>
*
* @section Documentation
*
* To generate documentation:
*
* <pre>$ make doc</pre>
**/
// }}}
// {{{ namespace
/**
* @namespace depage
* @brief depage cms
*
* @namespace depage::htmlform
* @brief htmlform class and autoloader
*
* @namespace depage::htmlform::abstracts
* @brief Abstract element classes
*
* @namespace depage::htmlform::elements
* @brief Classes for HTML input-elements
*
* All Classes in this namespace are HTML input-elements that can be added to
* instances of the @link depage::htmlform::htmlform htmlform-class@endlink,
* but also to also to @link depage::htmlform::elements::fieldset fieldsets@endlink
* and @link depage::htmlform::elements::step steps@endlink:
*
* @namespace depage::htmlform::exceptions
* @brief Htmlform exceptions
*
* @namespace depage::htmlform::validators
* @brief Validators for HTML input-elements
**/
namespace depage\htmlform;
// }}}
// {{{ autoloader
/**
* @brief PHP autoloader
*
* Autoloads classes by namespace. (requires PHP >= 5.3)
**/
function autoload($class) {
$class = str_replace('\\', '/', str_replace(__NAMESPACE__ . '\\', '', $class));
$file = __DIR__ . '/' . $class . '.php';
if (file_exists($file)) {
require_once($file);
}
}
spl_autoload_register(__NAMESPACE__ . '\autoload');
// }}}
/**
* @brief main interface to users
*
* The class htmlform is the main tool of the htmlform library. It generates
* input elements and container elements. It also contains the PHP session
* handlers.
*
* When you use <em>depage-forms</em> this is probably the only class you will
* instantiate directly.
*
* In general:
*
* @code
* <?php
* $form = new depage\htmlform\htmlform('simpleForm');
*
* // add form fields
* $form->addText('username', array('label' => 'User name', 'required' => true));
* $form->addEmail('email', array('label' => 'Email address'));
*
* // process form
* $form->process();
*
* if ($form->validate()) {
* // do something with your valid data
* var_dump($form->getValues());
* } else {
* // Form was empty or data was not valid:
* // Display the form.
* echo ($form);
* }
* ?>
* @endcode
*
* You can find a list of available input-class in @link depage::htmlform::elements
* elements@endlink.
*
* See examples at
* - @link simple.php @endlink - a simple form
**/
class htmlform extends abstracts\container {
// {{{ variables
/**
* @brief HTML form method attribute
* */
protected $method;
/**
* @brief HTML form action attribute
**/
protected $submitURL;
/**
* @brief Specifies where the user is redirected to, once the form-data is valid
**/
protected $successURL;
/**
* @brief Contains the submit button label of the form
**/
protected $label;
/**
* @brief Contains the additional class value of the form
**/
protected $class;
/**
* @brief Contains the name of the array in the PHP session, holding the form-data
**/
protected $sessionSlotName;
/**
* @brief PHP session handle
**/
protected $sessionSlot;
/**
* @brief Contains current step number
**/
private $currentStepId;
/**
* @brief Contains array of step object references
**/
private $steps = array();
/**
* @brief Time until session expiry (seconds)
**/
protected $ttl;
/**
* @brief Form validation result/status
**/
public $valid;
// }}}
// {{{ __construct()
/**
* @brief htmlform class constructor
*
* @param $name (string) form name
* @param $parameters (array) form parameters, HTML attributes
* @param $form (object) parent form object reference (not used in this case)
* @return void
**/
public function __construct($name, $parameters = array(), $form = null) {
$this->url = parse_url($_SERVER['REQUEST_URI']);
parent::__construct($name, $parameters, $this);
$this->currentStepId = (isset($_GET['step'])) ? $_GET['step'] : 0;
// check if there's an open session
if (!session_id()) {
session_set_cookie_params($this->ttl, "/");
session_start();
}
$this->sessionSlotName = $this->name . '-data';
$this->sessionSlot =& $_SESSION[$this->sessionSlotName];
$this->sessionExpiry();
$this->valid = (isset($this->sessionSlot['formIsValid'])) ? $this->sessionSlot['formIsValid'] : null;
// create a hidden input element to tell forms apart
$this->addHidden('formName', array('defaultValue' => $this->name));
$this->addChildElements();
}
// }}}
// {{{ setDefaults()
/**
* @brief Collects initial values across subclasses.
*
* The constructor loops through these and creates settable class
* attributes at runtime. It's a compact mechanism for initialising
* a lot of variables.
*
* @return void
**/
protected function setDefaults() {
parent::setDefaults();
$this->defaults['label'] = 'submit';
$this->defaults['cancelLabel'] = null;
$this->defaults['class'] = '';
$this->defaults['method'] = 'post';
// @todo adjust submit url for steps when used
$this->defaults['submitURL'] = $_SERVER['REQUEST_URI'];
$this->defaults['successURL'] = $_SERVER['REQUEST_URI'];
$this->defaults['cancelURL'] = $_SERVER['REQUEST_URI'];
$this->defaults['validator'] = null;
$this->defaults['ttl'] = 30 * 60; // 30 minutes
$this->defaults['jsValidation'] = 'blur';
$this->defaults['jsAutosave'] = 'false';
}
// }}}
// {{{ sessionExpiry()
/**
* @brief Deletes session when it expires.
*
* checks if session lifetime exceeds ttl value and deletes it. Updates
* timestamp.
*
* @return void
**/
private function sessionExpiry() {
if (isset($this->ttl) && is_numeric($this->ttl)) {
$timestamp = time();
if (
isset($this->sessionSlot['formTimestamp'])
&& ($timestamp - $this->sessionSlot['formTimestamp'] > $this->ttl)
) {
$this->clearSession();
$this->sessionSlot =& $_SESSION[$this->sessionSlotName];
}
$this->sessionSlot['formTimestamp'] = $timestamp;
}
}
// }}}
// {{{ addElement()
/**
* @brief Adds input or fieldset elements to htmlform.
*
* Calls parent class to generate an input element or a fieldset and add
* it to its list of elements.
*
* @param $type (string) input type or fieldset
* @param $name (string) name of the element
* @param $parameters (array) element attributes: HTML attributes, validation parameters etc.
* @return $newElement (object) element object
**/
protected function addElement($type, $name, $parameters) {
$this->checkElementName($name);
$newElement = parent::addElement($type, $name, $parameters);
if ($newElement instanceof elements\step) { $this->steps[] = $newElement; }
if ($newElement instanceof abstracts\input) { $this->updateInputValue($name); }
return $newElement;
}
// }}}
// {{{ updateInputValue()
/**
* @brief Updates the value of an associated input element
*
* Sets the input elements' value. If there is post-data - we'll use that
* to update the value of the input element and the session. If not - we
* take the value that's already in the session. If the value is neither in
* the session nor in the post-data - nothing happens.
*
* @param $name (string) name of the input element
* @return void
**/
public function updateInputValue($name) {
// if it's a post, take the value from there and save it to the session
if (
isset($_POST['formName']) && ($_POST['formName'] === $this->name)
&& $this->inCurrentStep($name)
) {
if ($this->getElement($name) instanceof elements\file) {
// handle uploaded file
$oldValue = isset($this->sessionSlot[$name]) ? $this->sessionSlot[$name] : null;
$this->sessionSlot[$name] = $this->getElement($name)->handleUploadedFiles($oldValue);
} else {
// save value
$value = isset($_POST[$name]) ? $_POST[$name] : null;
$this->sessionSlot[$name] = $this->getElement($name)->setValue($value);
}
}
// if it's not a post, try to get the value from the session
else if (isset($this->sessionSlot[$name])) {
$this->getElement($name)->setValue($this->sessionSlot[$name]);
}
}
// }}}
// {{{ inCurrentStep()
/**
* @brief Checks if the element named $name is in the current step.
*
* @param $name (string) name of element
* @return (bool) says wether it's in the current step
**/
private function inCurrentStep($name) {
return in_array($this->getElement($name), $this->getCurrentElements());
}
// }}}
// {{{ setCurrentStep()
/**
* @brief Validates step number of GET request.
*
* Validates step number of the GET request. If it's out of range it's
* reset to the number of the first invalid step. (only to be used after
* the form is completely created, because the step elements have to be
* counted)
*
* @return void
**/
private function setCurrentStep() {
if (!is_numeric($this->currentStepId)
|| ($this->currentStepId > count($this->steps) - 1)
|| ($this->currentStepId < 0)
) {
$this->currentStepId = $this->getFirstInvalidStep();
}
}
// }}}
// {{{ getSteps()
/**
* @brief Returns an array of steps
*
* @return (array) step objects
**/
public function getSteps() {
return $this->steps;
}
// }}}
// {{{ getCurrentStepId()
/**
* @brief Returns the current step id
*
* @return (int) current step
**/
public function getCurrentStepId() {
return $this->currentStepId;
}
// }}}
// {{{ getCurrenElements()
/**
* @brief Returns an array of input elements contained in the current step.
*
* @return (array) element objects
**/
private function getCurrentElements() {
$currentElements = array();
foreach($this->elements as $element) {
if ($element instanceof elements\fieldset) {
if (
!($element instanceof elements\step)
|| (isset($this->steps[$this->currentStepId]) && ($element == $this->steps[$this->currentStepId]))
) {
$currentElements = array_merge($currentElements, $element->getElements());
}
} else {
$currentElements[] = $element;
}
}
return $currentElements;
}
// }}}
// {{{ __toString()
/**
* @brief Renders form to HTML.
*
* Renders the htmlform object to HTML code. If the form contains elements
* it calls their rendering methods.
*
* @return (string) HTML code
**/
public function __toString() {
$renderedElements = '';
$label = $this->htmlLabel();
$cancellabel = $this->htmlCancelLabel();
$class = $this->htmlClass();
$method = $this->htmlMethod();
$submitURL = $this->htmlSubmitURL();
$jsValidation = $this->htmlJsValidation();
$jsAutosave = $this->jsAutosave === true ? "true" : $this->htmlJsAutosave();
foreach($this->elementsAndHtml as $element) {
// leave out inactive step elements
if (
!($element instanceof elements\step)
|| (isset($this->steps[$this->currentStepId]) && $this->steps[$this->currentStepId] == $element)
) {
$renderedElements .= $element;
}
}
if (!is_null($this->cancelLabel)) {
$cancel = "<p id=\"{$this->name}-cancel\" class=\"cancel\"><input type=\"submit\" name=\"formSubmit\" value=\"{$cancellabel}\"></p>\n";
} else {
$cancel = "";
}
return "<form id=\"{$this->name}\" name=\"{$this->name}\" class=\"depage-form {$class}\" method=\"{$method}\" action=\"{$submitURL}\" data-jsvalidation=\"{$jsValidation}\" data-jsautosave=\"{$jsAutosave}\" enctype=\"multipart/form-data\">" . "\n" .
$renderedElements .
"<p id=\"{$this->name}-submit\" class=\"submit\"><input type=\"submit\" name=\"formSubmit\" value=\"{$label}\"></p>" . "\n" .
$cancel .
"</form>";
}
// }}}
// {{{ process()
/**
* @brief Calls form validation and handles redirects.
*
* Implememts the Post/Redirect/Get strategy. Redirects to success Address
* on succesful validation otherwise redirects to first invalid step or
* back to form.
*
* @return void
*
* @see validate()
**/
public function process() {
$this->setCurrentStep();
// if there's post-data from this form
if (isset($_POST['formName']) && ($_POST['formName'] === $this->name)) {
if (!is_null($this->cancelLabel) && isset($_POST['formSubmit']) && $_POST['formSubmit'] === $this->cancelLabel) {
$this->clearSession();
$this->redirect($this->cancelURL);
} else if ($this->validate()) {
$this->redirect($this->successURL);
} else {
$firstInvalidStep = $this->getFirstInvalidStep();
$urlStepParameter = ($firstInvalidStep == 0) ? $this->buildUrlQuery('') : $this->buildUrlQuery('step=' . $firstInvalidStep);
$this->redirect($this->url['path'] . $urlStepParameter);
}
}
}
// }}}
// {{{ buildUrlQuery()
/**
* @brief Adding step parameter to already existing query
*
* @return new query
**/
public function buildUrlQuery($step_query = '') {
//if there is query
$query = '';
if (isset($this->url['query']) && $this->url['query']!="") {
//decoding query string
$query = html_entity_decode($this->url['query']);
//parsing the query into an array
parse_str($query, $queryParts);
//remove any step argument
if (isset($queryParts["step"])) unset($queryParts["step"]);
//building again the query
$query = http_build_query($queryParts);
//adding question mark
$query = "?".$query;
//adding the extra query
$query .= isset($step_query)?'&'.$step_query:'';
} else {
$query = isset($step_query)?'?'.$step_query:'';
}
return $query;
}
// }}}
// {{{ getFirstInvalidStep()
/**
* @brief Returns first step that didn't pass validation.
*
* Checks steps consecutively and returns the number of the first one that
* isn't valid (steps need to be submitted at least once to count as valid).
* Form must have been validated before calling this method.
*
* @return $stepNumber (int) number of first invalid step
**/
public function getFirstInvalidStep() {
if ( count($this->steps ) > 0) {
foreach ( $this->steps as $stepNumber => $step ) {
if ( !$step->valid ) {
return $stepNumber;
}
}
/**
* If there aren't any invalid steps there must be a fieldset
* directly attached to the form that's invalid. In this case we
* don't want to jump back to the first step. Hence, this little
* hack.
**/
return count($this->steps) - 1;
} else {
return 0;
}
}
// }}}
// {{{ redirect()
/**
* @brief Redirects Browser to a different URL.
*
* @param $url (string) url to redirect to
*/
public function redirect($url) {
if (isset($_POST['formAutosave']) && $_POST['formAutosave'] === "true") {
// don't redirect > it's from ajax
} else {
header('Location: ' . $url);
die( "Tried to redirect you to <a href=\"$url\">$url</a>");
}
}
// }}}
// {{{ validate()
/**
* @brief Validates the forms subelements.
*
* Form validation - validates form elements returns validation result and
* writes it to session. Also calls custom validator if available.
*
* @return (bool) validation result
*
* @see process()
**/
public function validate() {
// onValidate hook for custom required/validation rules
$this->valid = $this->onValidate();
$this->valid = $this->valid && $this->validateAutosave();
if ($this->valid && !is_null($this->validator)) {
if (is_callable($this->validator)) {
$this->valid = call_user_func($this->validator, $this, $this->getValues());
} else {
throw new exceptions\validatorNotCallable("The validator paramater must be callable");
}
}
// save validation-state in session
$this->sessionSlot['formIsValid'] = $this->valid;
return $this->valid;
}
// }}}
// validateAutosave() {{{
/**
* If the form is autosaving the validation property is defaulted to false.
*
* This function returns the actual state of input validation.
* It can therefore be used to test autosave fields are correct without forcing
* the form save.
*
* @return bool $part_valid - whether the autosave postback data is valid
*/
public function validateAutosave(){
parent::validate();
$part_valid = $this->valid;
// save data in session when autosaving but don't validate successfully
if ((isset($_POST['formAutosave']) && $_POST['formAutosave'] === "true")
|| (isset($this->sessionSlot['formIsAutosaved'])
&& $this->sessionSlot['formIsAutosaved'] === true)) {
$this->valid = false;
}
// save whether form was autosaved the last time
$this->sessionSlot['formIsAutosaved'] = isset($_POST['formAutosave']) && $_POST['formAutosave'] === "true";
return $part_valid;
}
// }}}
// {{{ isEmpty()
/**
* @brief Returns wether form has been submitted before or not.
*
* @return (bool) session status
**/
public function isEmpty() {
return !isset($this->sessionSlot['formName']);
}
// }}}
// {{{ populate()
/**
* @brief Fills subelement values.
*
* Allows to manually populate the forms' input elements with values by
* parsing an array of name-value pairs.
*
* @param $data (array) input element names (key) and values (value)
* @return void
**/
public function populate($data = array()) {
foreach($data as $name => $value) {
$element = $this->getElement($name);
if ($element) {
$element->setDefaultValue($value);
}
}
}
// }}}
// {{{ getValues()
/**
* @brief Gets form-data from current PHP session.
*
* @return (array) form-data
**/
public function getValues() {
if (isset($this->sessionSlot)) {
// remove internal attributes from values
return array_diff_key($this->sessionSlot, array(
'formIsValid' => '',
'formIsAutosaved' => '',
'formName' => '',
'formTimestamp' => '',
));
} else {
return null;
}
}
// }}}
// {{{ getValuesWithLabel()
/**
* @brief Gets form-data from current PHP session but also contain elemnt labels.
*
* @return (array) form-data with labels
**/
public function getValuesWithLabel() {
//get values first
$values = $this->getValues();
$values_with_label =array();
if (isset($values)) {
foreach ($values as $element => $value) {
$elem = $this->getElement($element);
if ($elem) $values_with_label[$element] = array("value"=>$value, "label"=>$elem->getLabel());
}
return $values_with_label;
} else {
return null;
}
}
// }}}
// {{{ checkElementName()
/**
* @brief Checks for duplicate subelement names.
*
* Checks within the form if an input element or fieldset name is already
* taken. If so, it throws an exception.
*
* @param $name name to check
* @return void
**/
public function checkElementName($name) {
foreach($this->getElements(true) as $element) {
if ($element->getName() === $name) {
throw new exceptions\duplicateElementNameException("Element name \"{$name}\" already in use.");
}
}
}
// }}}
// {{{ clearSession()
/**
* @brief Deletes the current forms' PHP session data.
*
* @return void
**/
public function clearSession() {
$this->clearValue();
unset($_SESSION[$this->sessionSlotName]);
unset($this->sessionSlot);
}
// }}}
// {{{ onValidate()
/**
* @brief Validation hook
*
* Can be overridden with custom validation rules, field-required rules etc.
*
* @return void
*
* @see validate()
**/
protected function onValidate() {
return true;
}
// }}}
}
// {{{ example page links
/**
* @example elements.php
* @brief Various element examples
*
* Demonstrates the use of all element types that are fully implemented.
* Includes examples of element specific options.
*
* @htmlonly<iframe class="example" seamless="seamless" src="../examples/elements.php"></iframe>@endhtmlonly
**/
/**
* @example js-validation.php
* @brief Client-side JavaScript validation
*
* Demonstrates client-side validation. Fields are validated when they lose
* focus. The regular expression has to match the entire string (as in HTML5
* patterns). Contrary to PHP preg_match() "/[a-z]/" does not match "aaa".
*
* @htmlonly<iframe class="example" seamless="seamless" src="../examples/js-validation.php"></iframe>@endhtmlonly
**/
/**
* @example lists.php
* @brief Option list examples
*
* Multiple, single and text input elements have option lists. Here are some
* more detailed examples.
*
* @htmlonly<iframe class="example" seamless="seamless" src="../examples/lists.php"></iframe>@endhtmlonly
**/
/**
* @example populate.php
* @brief Populate form example
*
* The htmlform->populate method provides a comfortable way to fill in
* default values before displaying the form. It's more convenient than setting
* the 'defaultValue' parameter for each input element individually.
*
* @htmlonly<iframe class="example" seamless="seamless" src="../examples/populate.php"></iframe>@endhtmlonly
**/
/**
* @example reallife.php
* @brief (almost) real life depage-forms example
*
* Contains a common personal information form. Some elements are set required
* and the username has a minimum length.
*
* @htmlonly<iframe class="example" seamless="seamless" src="../examples/reallife.php"></iframe>@endhtmlonly
**/
/**
* @example redirect.php
* @brief Redirect to success page example
*
* Once the form is validated, it can also be redirected to another URL. This
* can be done by setting the 'successURL' parameter in the form.
*
* @htmlonly<iframe class="example" seamless="seamless" src="../examples/redirect.php"></iframe>@endhtmlonly
*
* @include redirect-success.php
**/
/**
* @example session-timeout.php
* @brief Form expiry example
*
* One can lower the lifetime of the forms session by setting the 'ttl' value.
* Setting this higher than the PHP session length (default around 30min) has
* no effect.
*
* @htmlonly<iframe class="example" seamless="seamless" src="../examples/session-timeout.php"></iframe>@endhtmlonly
**/
/**
* @example simple.php
* @brief Simple form example
*
* Contains text and email input elements and demonstrates form processing and
* validation. In this simple case none of the elements are set required, so an
* empty form would also be valid.
*
* @htmlonly<iframe class="example" seamless="seamless" src="../examples/simple.php"></iframe>@endhtmlonly
**/
/**
* @example steps.php
* @brief Steps example
*
* This demonstrates dividing the form into separate pages using step
* container elements. As usual the form itself can only be valid when all
* its input elements are valid.
* It is also possible to attach input elements directly to the form (outside
* any step container). These elements are visible on every step.
*
* @htmlonly<iframe class="example" seamless="seamless" src="../examples/steps.php"></iframe>@endhtmlonly
**/
/**
* @example subclass.php
* @brief Form subclass example
*
* It's also possible to override the htmlform class and add elements in the
* constructor. This way we can build reusable form classes or add custom rules
* to the form validation.
*
* @htmlonly<iframe class="example" seamless="seamless" src="../examples/subclass.php"></iframe>@endhtmlonly
**/
// }}}
/* vim:set ft=php sw=4 sts=4 fdm=marker et : */