Allow preseeding form fields from URL parameters
This commit is contained in:
parent
8bacd9cfb0
commit
45ddd15ecf
2 changed files with 9 additions and 0 deletions
8
Form.php
8
Form.php
|
@ -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);
|
||||
|
|
1
test.php
1
test.php
|
@ -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") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue