Allow preseeding form fields from URL parameters

This commit is contained in:
Nero 2019-09-09 12:34:54 +00:00
parent 8bacd9cfb0
commit 45ddd15ecf
2 changed files with 9 additions and 0 deletions

View File

@ -29,6 +29,14 @@ class Form {
}
}
public function preseedFromUrl() {
foreach ($this->fields as $name=>$field) {
if (isset($_GET[$name])) {
$field->setValue($_GET[$name]);
}
}
}
public function loadFromEnv() {
foreach ($this->fields as $name=>$field) {
$field->loadFromEnv($name);

View File

@ -23,6 +23,7 @@ $form = new Post\Form(array(
"select" => new Post\SelectField(array("options"=>array("0"=>"false","1"=>"true")))
));
$form->preseedFromUrl();
$form->denyCsrf();
if ($_SERVER["REQUEST_METHOD"]=="POST") {