mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 11:06:02 +02:00
FEATURE: added a page type for testing multi step form
This commit is contained in:
parent
b90c61558a
commit
a0fb3d463f
75
code/TestMultiForm.php
Normal file
75
code/TestMultiForm.php
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
class TestMultiForm extends MultiForm {
|
||||||
|
protected static $start_step = 'TestMultiFormStepOne';
|
||||||
|
|
||||||
|
function finish($data, $form) {
|
||||||
|
parent::finish($data, $form);
|
||||||
|
|
||||||
|
$savedSteps = $this->getSavedSteps();
|
||||||
|
|
||||||
|
$savedData = array();
|
||||||
|
foreach($savedSteps as $step) {
|
||||||
|
$savedData = array_merge($savedData, $step->loadData());
|
||||||
|
}
|
||||||
|
|
||||||
|
$fields = new FieldSet();
|
||||||
|
$fields->push(new LiteralField("Heading", "<h3>You have submitted the following information:</h3>"));
|
||||||
|
|
||||||
|
foreach($savedData as $key=>$value) {
|
||||||
|
$fields->push(new LiteralField($key . '_copy', "<p><strong>$key</strong> $value</p>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Director::redirect(Director::BaseURL() . $this->Controller()->URLSegment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestMultiFormStepOne extends MultiFormStep {
|
||||||
|
protected static $next_steps = 'TestMultiFormStepTwo';
|
||||||
|
|
||||||
|
function getFields() {
|
||||||
|
return new FieldSet(
|
||||||
|
new TextField('FirstName', 'First name'),
|
||||||
|
new TextField('Surname', 'Surname')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestMultiFormStepTwo extends MultiFormStep {
|
||||||
|
protected static $next_steps = 'TestMultiFormStepThree';
|
||||||
|
|
||||||
|
function getFields() {
|
||||||
|
|
||||||
|
return new FieldSet(
|
||||||
|
new TextField('Email', 'Email'),
|
||||||
|
new TextField('Address', 'Address')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestMultiFormStepThree extends MultiFormStep {
|
||||||
|
protected static $is_final_step = true;
|
||||||
|
|
||||||
|
function getFields() {
|
||||||
|
$form = $this->getForm();
|
||||||
|
$savedSteps = $form->getSavedSteps();
|
||||||
|
|
||||||
|
$savedData = array();
|
||||||
|
foreach($savedSteps as $step) {
|
||||||
|
$savedData = array_merge($savedData, $step->loadData());
|
||||||
|
}
|
||||||
|
|
||||||
|
$fields = new FieldSet();
|
||||||
|
$fields->push(new LiteralField("Heading", "<h3>You have submitted the following information:</h3>"));
|
||||||
|
|
||||||
|
foreach($savedData as $key=>$value) {
|
||||||
|
if(preg_match("/_copy$/", $key)) continue;
|
||||||
|
|
||||||
|
$fields->push(new LiteralField($key . '_copy', "<p><strong>$key</strong> $value</p>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
13
code/TestMultiFormPage.php
Normal file
13
code/TestMultiFormPage.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
class TestMultiFormPage extends Page {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestMultiFormPage_Controller extends Page_Controller {
|
||||||
|
|
||||||
|
function Form() {
|
||||||
|
$form = new TestMultiForm($this, 'Form', new FieldSet(), new FieldSet());
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user