silverstripe-frameworktest/code/multiform/Page2MultiForm.php

76 lines
2.2 KiB
PHP
Raw Normal View History

2010-03-10 21:20:44 +01:00
<?php
use SilverStripe\Control\HTTPResponse;
use SilverStripe\ORM\DataObject;
2016-07-20 00:34:52 +02:00
use SilverStripe\Security\Member;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
2015-12-17 21:20:49 +01:00
class Page2MultiForm extends MultiForm
{
2016-07-20 00:34:52 +02:00
2015-12-17 21:20:49 +01:00
public static $start_step = 'Page2PersonalDetailsFormStep';
2016-07-20 00:34:52 +02:00
public function finish(array $data, Form $form): HTTPResponse
2015-12-17 21:20:49 +01:00
{
parent::finish($data, $form);
$steps = DataObject::get('MultiFormStep', "SessionID = {$this->session->ID}");
if ($steps) {
foreach ($steps as $step) {
2017-05-18 07:11:01 +02:00
if ($step->ClassName == 'Page2PersonalDetailsFormStep') {
2015-12-17 21:20:49 +01:00
$member = new Member();
$data = $step->loadData();
if ($data) {
$member->update($data);
$member->write();
}
}
2010-03-10 21:20:44 +01:00
2017-05-18 07:11:01 +02:00
if ($step->ClassName == 'Page2OrganisationDetailsFormStep') {
2015-12-17 21:20:49 +01:00
$organisation = new Organisation();
$data = $step->loadData();
if ($data) {
$organisation->update($data);
if ($member && $member->ID) {
$organisation->MemberID = $member->ID;
}
$organisation->write();
}
}
2010-03-10 21:20:44 +01:00
2015-12-17 21:20:49 +01:00
// Debug::show($step->loadData()); // Shows the step data (unserialized by loadData)
}
}
$controller = $this->getController();
return $controller->redirect($controller->Link() . 'finished');
2015-12-17 21:20:49 +01:00
}
}
2010-03-10 21:20:44 +01:00
2015-12-17 21:20:49 +01:00
class Page2PersonalDetailsFormStep extends MultiFormStep
{
2016-07-20 00:34:52 +02:00
2015-12-17 21:20:49 +01:00
public static $next_steps = 'Page2OrganisationDetailsFormStep';
2016-07-20 00:34:52 +02:00
2015-12-17 21:20:49 +01:00
public function getFields()
{
return new FieldList(
new TextField('FirstName', 'First name'),
new TextField('Surname', 'Surname')
);
}
2010-03-10 21:20:44 +01:00
}
2015-12-17 21:20:49 +01:00
class Page2OrganisationDetailsFormStep extends MultiFormStep
{
2016-07-20 00:34:52 +02:00
2015-12-17 21:20:49 +01:00
public static $is_final_step = true;
2010-03-10 21:20:44 +01:00
2015-12-17 21:20:49 +01:00
public function getFields()
{
return new FieldList(
new TextField('OrganisationName', 'Organisation Name')
);
}
2010-03-10 21:20:44 +01:00
}