| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
include_once 'patExampleGen/prepend.php'; |
|---|
| 19 |
$exampleGen->displayHead( 'Example' ); |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
require_once $neededFiles['patForms']; |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
require_once $neededFiles['patErrorManager']; |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
$elementsDefinition = array( |
|---|
| 36 |
'xmess' => array( |
|---|
| 37 |
'type' => 'Date', |
|---|
| 38 |
'attributes' => array( |
|---|
| 39 |
'required' => 'yes', |
|---|
| 40 |
'display' => 'yes', |
|---|
| 41 |
'edit' => 'yes', |
|---|
| 42 |
'label' => 'X-Mess eve', |
|---|
| 43 |
'title' => 'X-Mess', |
|---|
| 44 |
'description' => 'Tell me when you celebrate x-mess.', |
|---|
| 45 |
'dateformat' => '%d.%m.%Y %H:%M', |
|---|
| 46 |
'default' => '2001-12-24 07:30:42', |
|---|
| 47 |
'onchange' => 'alert( pfe_xmess.getDate() )', |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
$form =& patForms::createForm( $elementsDefinition, array( 'name' => 'myForm' ) ); |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
$renderer =& patForms::createRenderer( "Array" ); |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
$form->setRenderer( $renderer ); |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
$form->setAutoValidate( 'save' ); |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
$elements = $form->renderForm(); |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
if( $form->isSubmitted() ) |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
$errors = $form->getValidationErrors(); |
|---|
| 75 |
$errors ) |
|---|
| 76 |
|
|---|
| 77 |
"<b>patForms:</b> validation failed. Errors:<br><br>"; |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
foreach( $errors as $elementName => $elementErrors ) |
|---|
| 81 |
|
|---|
| 82 |
$elementErrors ) ) |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
'Field: <b>'.$elementName.'</b>'; |
|---|
| 86 |
"<pre>"; |
|---|
| 87 |
print_r( $elementErrors ); |
|---|
| 88 |
"</pre>"; |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
"<b>patForms:</b> validation successful.<br><br>"; |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
echo $form->serializeStart(); |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
foreach( $elements as $element ) |
|---|
| 105 |
|
|---|
| 106 |
$element["label"]."<br>"; |
|---|
| 107 |
"<div>".$element["element"]."</div>"; |
|---|
| 108 |
"<i>".$element["description"]."</i><br><br>"; |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
echo '<input type="submit" name="save" value="Save form"/><br><br>'; |
|---|
| 113 |
$form->serializeEnd(); |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
$exampleGen->displayFooter(); |
|---|
| 120 |
?> |
|---|