silverstripe-frameworktest/code/multiform/TestMultiForm.php
Normann Lou 0a4f22a08f ENHANCEMENT: use FieldList constructor to replace FieldSet constructor for SilverStripe 3
ENHANCEMENT: use FormActioin constructor to replace ImageFormAction constructor for SilverStripe 3
2012-06-30 00:27:32 +12:00

78 lines
1.9 KiB
PHP

<?php
class TestMultiForm extends MultiForm {
public 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 FieldList();
$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>"));
}
Session::set("MultiFormMessage", "Your information has been submitted.");
Director::redirect(Director::BaseURL() . $this->Controller()->URLSegment);
}
}
class TestMultiFormStepOne extends MultiFormStep {
public static $next_steps = 'TestMultiFormStepTwo';
function getFields() {
return new FieldList(
new TextField('FirstName', 'First name'),
new TextField('Surname', 'Surname')
);
}
}
class TestMultiFormStepTwo extends MultiFormStep {
public static $next_steps = 'TestMultiFormStepThree';
function getFields() {
return new FieldList(
new TextField('Email', 'Email'),
new TextField('Address', 'Address')
);
}
}
class TestMultiFormStepThree extends MultiFormStep {
public 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 FieldList();
$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;
}
}