Allow preseeding form fields from URL parameters
This commit is contained in:
parent
8bacd9cfb0
commit
45ddd15ecf
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() {
|
public function loadFromEnv() {
|
||||||
foreach ($this->fields as $name=>$field) {
|
foreach ($this->fields as $name=>$field) {
|
||||||
$field->loadFromEnv($name);
|
$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")))
|
"select" => new Post\SelectField(array("options"=>array("0"=>"false","1"=>"true")))
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$form->preseedFromUrl();
|
||||||
$form->denyCsrf();
|
$form->denyCsrf();
|
||||||
|
|
||||||
if ($_SERVER["REQUEST_METHOD"]=="POST") {
|
if ($_SERVER["REQUEST_METHOD"]=="POST") {
|
||||||
|
Loading…
Reference in New Issue
Block a user