function backToForm($url, $errors) { list($msg, $fielderrs) = FieldError::listExtract($errors); $_SESSION["postVars"] = mkPostVars(); $_SESSION["pageErrors"] = $fielderrs; if (strchr($url, '?')) { header("Location: " . $url . "&msg=" . U($msg)); } else { header("Location: " . $url . "?msg=" . U($msg)); } exit; }
function display($params) { $defaults = array('title' => '', 'name' => NULL, 'method' => 'post', 'enctype' => NULL, 'action' => NULL, 'submit' => Form::T('Submit'), 'cancel' => NULL, 'fields' => array(), 'values' => array(), 'errors' => array()); $params = array_merge($defaults, $params); if (!$params['action']) { Fatal::internalError(Form::T("No form action")); } $fields = Form::_cleanFields($params['fields']); echo "<form method='" . H($params['method']) . "' action='" . H($params['action']) . "'"; if ($params['name']) { echo ' name="' . H($params['name']) . '" id="' . H($params['name']) . '"'; } if ($params['enctype']) { echo ' enctype="' . H($params['enctype']) . '"'; } echo ">\n"; echo '<input type="hidden" name="_posted" value="1" />' . "\n"; list($msg, $errors) = FieldError::listExtract($params['errors']); $rows = array(); foreach ($fields as $f) { if (!isset($params['values'][$f['name']])) { $f['value'] = $f['default']; } else { $f['value'] = $params['values'][$f['name']]; } $html = Form::_inputField($f); if (isset($errors[$f['name']])) { $error = $errors[$f['name']]; } else { $error = NULL; } if ($f['type'] == 'hidden') { if ($error) { Fatal::internalError(Form::T("Unexpected hidden field error: %error%", array('error' => $error))); } echo $html; } else { $rows[] = array('title' => $f['title'], 'html' => $html, 'error' => $error); } } echo '<table class="form">'; echo '<tr><th colspan="2" class="title">' . H($params['title']) . '</td></tr>'; if ($msg) { echo '<tr><td colspan="2" class="error">' . H($msg) . '</td></tr>'; } foreach ($rows as $r) { echo "<tr>"; echo "<th>" . H($r['title']) . "</th>"; if ($r['error']) { $err = '<span class="error">' . H($r['error']) . '</span><br />'; } else { $err = ''; } echo '<td>' . $err . $r['html'] . "</td></tr>\n"; } echo "<tr><td></td><td class='buttons'>"; echo "<input class='button' type='submit' value='" . H($params['submit']) . "' />\n"; if ($params['cancel']) { echo '<a class="small_button" href="' . H($params['cancel']) . '">' . Form::T("Cancel") . '</a> '; } echo '</td></tr></table>'; echo "</form>\n"; }