2010-03-03 23:24:02 +01:00
|
|
|
<?php
|
2016-09-07 07:10:55 +02:00
|
|
|
|
|
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
use SilverStripe\Forms\LiteralField;
|
|
|
|
use SilverStripe\Control\Session;
|
|
|
|
use SilverStripe\Control\Director;
|
2022-10-19 01:00:04 +02:00
|
|
|
use SilverStripe\Control\HTTPResponse;
|
|
|
|
use SilverStripe\Forms\Form;
|
2016-09-07 07:10:55 +02:00
|
|
|
use SilverStripe\Forms\TextField;
|
2015-12-17 21:20:49 +01:00
|
|
|
class TestMultiForm extends MultiForm
|
|
|
|
{
|
|
|
|
public static $start_step = 'TestMultiFormStepOne';
|
|
|
|
|
2022-10-19 01:00:04 +02:00
|
|
|
public function finish(array $data, Form $form): HTTPResponse
|
2015-12-17 21:20:49 +01:00
|
|
|
{
|
|
|
|
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.");
|
|
|
|
|
2022-10-19 01:00:04 +02:00
|
|
|
return $this->Controller()->redirect(Director::BaseURL() . $this->Controller()->URLSegment);
|
2015-12-17 21:20:49 +01:00
|
|
|
}
|
2010-03-03 23:24:02 +01:00
|
|
|
}
|
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
class TestMultiFormStepOne extends MultiFormStep
|
|
|
|
{
|
|
|
|
public static $next_steps = 'TestMultiFormStepTwo';
|
|
|
|
|
|
|
|
public function getFields()
|
|
|
|
{
|
|
|
|
return new FieldList(
|
|
|
|
new TextField('FirstName', 'First name'),
|
|
|
|
new TextField('Surname', 'Surname')
|
|
|
|
);
|
|
|
|
}
|
2010-03-03 23:24:02 +01:00
|
|
|
}
|
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
class TestMultiFormStepTwo extends MultiFormStep
|
|
|
|
{
|
|
|
|
public static $next_steps = 'TestMultiFormStepThree';
|
|
|
|
|
|
|
|
public function getFields()
|
|
|
|
{
|
|
|
|
return new FieldList(
|
|
|
|
new TextField('Email', 'Email'),
|
|
|
|
new TextField('Address', 'Address')
|
|
|
|
);
|
|
|
|
}
|
2010-03-03 23:24:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
class TestMultiFormStepThree extends MultiFormStep
|
|
|
|
{
|
|
|
|
public static $is_final_step = true;
|
|
|
|
|
|
|
|
public 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) {
|
2022-04-13 00:31:07 +02:00
|
|
|
if (preg_match("/_copy$/", $key ?? '')) {
|
2015-12-17 21:20:49 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$fields->push(new LiteralField($key . '_copy', "<p><strong>$key</strong> $value</p>"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
2010-03-03 23:24:02 +01:00
|
|
|
}
|