| 1 |
<?php |
|---|
| 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 |
function displayErrors( &$form ) |
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
$errors = $form->getValidationErrors(); |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
if ($errors) { |
|---|
| 36 |
'<div class="piErrors">'; |
|---|
| 37 |
' <div class="piErrorsTitle">Validation failed</div>'; |
|---|
| 38 |
' <div class="piErrorsContent">'; |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
foreach ($errors as $elementName => $elementErrors) { |
|---|
| 43 |
$element =& $form->getElementByName( $elementName ); |
|---|
| 44 |
|
|---|
| 45 |
is_array($element)) { |
|---|
| 46 |
$element = $element[0]; |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
is_object($element)) { |
|---|
| 50 |
patErrorManager::raiseError("patExampleGen::0001", "The getElementByName() method did not return an element."); |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
foreach ($elementErrors as $row => $error) { |
|---|
| 57 |
' <div class="piError">'; |
|---|
| 58 |
' <b>'.$element->getAttribute( 'label' ).':</b> '.$error['message'].' ('.$error['element'].' element error #'.$error['code'].')<br/>'; |
|---|
| 59 |
' </div>'; |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
' </div>'; |
|---|
| 64 |
'</div>'; |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
else |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
'<div class="piHint">Validation successful.</div>'; |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
function displayForm( &$form, $elements ) |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
echo $form->serializeStart(); |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
foreach( $elements as $element ) |
|---|
| 97 |
|
|---|
| 98 |
'<div style="margin-bottom:8px;">'; |
|---|
| 99 |
$element['label']."<br>"; |
|---|
| 100 |
"<div>".$element["element"]."</div>"; |
|---|
| 101 |
|
|---|
| 102 |
$element["description"] ) ) |
|---|
| 103 |
|
|---|
| 104 |
"<i>".$element["description"]."</i><br>"; |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
'</div>'; |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
echo '<input type="submit" name="save" value="Save form"/><br><br>'; |
|---|
| 112 |
$form->serializeEnd(); |
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
if( $form->isSubmitted() ) { |
|---|
| 117 |
$els =& $form->getElements(); |
|---|
| 118 |
$cnt = count( $els ); |
|---|
| 119 |
|
|---|
| 120 |
'<div class="piValues">'; |
|---|
| 121 |
' <div class="piValuesTitle">Submitted form values</div>'; |
|---|
| 122 |
' <div class="piValuesContent">'; |
|---|
| 123 |
' <table cellpadding="2" cellspacing="0" border="0">'; |
|---|
| 124 |
|
|---|
| 125 |
$i = 0; $i < $cnt; $i++ ) { |
|---|
| 126 |
'<tr valign="top">'; |
|---|
| 127 |
' <td>'.$els[$i]->getAttribute( 'label' ).'</td><td> : </td><td>'.var2string( $els[$i]->getValue() ).'</td>'; |
|---|
| 128 |
'</tr>'; |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
' </table>'; |
|---|
| 132 |
' </div>'; |
|---|
| 133 |
'</div>'; |
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
var2string( $subject ) |
|---|
| 138 |
|
|---|
| 139 |
is_object( $subject ) ) { |
|---|
| 140 |
$class = get_class( $subject ); |
|---|
| 141 |
'<i style="color:#666;">object</i> <span style="color:#006600;">"'.$class.'"</span>'; |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
is_int( $subject ) ) { |
|---|
| 145 |
'<i style="color:#666;">int</i> <span style="color:#003366;">'.$subject.'</span>'; |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
is_null( $subject ) ) { |
|---|
| 149 |
'<i style="color:#666;">null</i>'; |
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
is_array( $subject ) ) { |
|---|
| 153 |
$string = ''; |
|---|
| 154 |
$subject as $key => $val ) { |
|---|
| 155 |
$string .= str_repeat( ' ', 6 ).$key.' => '.var2string( $val ).'<br/>'; |
|---|
| 156 |
|
|---|
| 157 |
'<i style="color:#666;">array</i><span style="color:#006600;">(<br/>'.$string.');</span>'; |
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
is_bool( $subject ) ) { |
|---|
| 161 |
$display = 'true'; |
|---|
| 162 |
$bool === false ) { |
|---|
| 163 |
$display = 'false'; |
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
'<i style="color:#666">bool</i> <span style="color:#003366;">'.$display.'</span>'; |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
'<i style="color:#666;">'.gettype( $subject ).'</i> <span style="color:#006600;">"'.$subject.'"</span>'; |
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
?> |
|---|