73 lines
1.9 KiB
PHP
73 lines
1.9 KiB
PHP
<?php
|
|
// Increase verbosity
|
|
error_reporting(E_ALL);
|
|
ini_set("display_errors",1);
|
|
|
|
// All notices and warnings shall be fatal
|
|
set_error_handler("onError");
|
|
function onError($severity, $message, $file, $line) {
|
|
throw new ErrorException($message, 0, $severity, $file, $line);
|
|
}
|
|
|
|
// Autoload classes if available
|
|
spl_autoload_register(function ($class_name) {
|
|
include(str_replace('Post\\','',$class_name).'.php');
|
|
});
|
|
|
|
session_start();
|
|
|
|
$form = new Post\Form(array(
|
|
"string" => new Post\FormField(),
|
|
"secret" => new Post\SecretFormField(),
|
|
"file" => new Post\FileUpload(),
|
|
"select" => new Post\SelectField(array("options"=>array("0"=>"false","1"=>"true")))
|
|
));
|
|
|
|
$form->preseedFromUrl();
|
|
$form->denyCsrf();
|
|
|
|
if ($_SERVER["REQUEST_METHOD"]=="POST") {
|
|
$form->loadFromEnv();
|
|
$t=$form;
|
|
}
|
|
|
|
?><!DOCTYPE html>
|
|
<html>
|
|
<body>
|
|
<form method=POST enctype="<?php echo($form->getEnctype()); ?>" action="<?php echo($form->action); ?>">
|
|
<table border=1>
|
|
<?php foreach($form->fields as $name=>$field) { ?>
|
|
<tr>
|
|
<td><?php echo($name); ?></td>
|
|
<td>
|
|
<?php
|
|
if ($field instanceof Post\FileUpload) {
|
|
echo('<input name='.$name.' type=file />');
|
|
} elseif ($field instanceof Post\HiddenFormField) {
|
|
echo('<input name='.$name.' type=hidden value="'.htmlspecialchars($field->getValue()).'" />');
|
|
} elseif ($field instanceof Post\SelectField) {
|
|
echo('<select name='.$name.'>');
|
|
foreach ($field->options as $k=>$v) {
|
|
echo('<option value="'.htmlspecialchars($k).'"'.($k==$field->getValue()?" selected=selected":"").'>'.htmlspecialchars($v).'</option>');
|
|
}
|
|
echo('</select>');
|
|
} elseif ($field instanceof Post\SecretFormField) {
|
|
echo('<input name='.$name.' type=password />');
|
|
} else {
|
|
echo('<input name='.$name.' type=text value="'.htmlspecialchars($field->getValue()).'" />');
|
|
}
|
|
?>
|
|
</td>
|
|
</tr>
|
|
<?php } ?>
|
|
<tr><td></td><td><button type=submit>submit</button></td></tr>
|
|
</table>
|
|
</form>
|
|
<?php
|
|
if (isset($t)) {
|
|
echo("<pre>".htmlspecialchars(var_export($form, true))."</pre>");
|
|
}
|
|
?>
|
|
</body>
|
|
</html>
|