Add example file
This commit is contained in:
parent
92c5899afe
commit
6a4b00086b
54
test.php
Normal file
54
test.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
$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->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>
|
Loading…
Reference in New Issue
Block a user