silverstripe-frameworktest/code/multiform/Page2MultiForm.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

65 lines
1.7 KiB
PHP

<?php
class Page2MultiForm extends MultiForm {
public static $start_step = 'Page2PersonalDetailsFormStep';
public function finish($data, $form) {
parent::finish($data, $form);
$steps = DataObject::get('MultiFormStep', "SessionID = {$this->session->ID}");
if($steps) {
foreach($steps as $step) {
if($step->class == 'Page2PersonalDetailsFormStep') {
$member = new Member();
$data = $step->loadData();
if($data) {
$member->update($data);
$member->write();
}
}
if($step->class == 'Page2OrganisationDetailsFormStep') {
$organisation = new Organisation();
$data = $step->loadData();
if($data) {
$organisation->update($data);
if($member && $member->ID) $organisation->MemberID = $member->ID;
$organisation->write();
}
}
// Debug::show($step->loadData()); // Shows the step data (unserialized by loadData)
}
}
$controller = $this->getController();
$controller->redirect($controller->Link() . 'finished');
}
}
class Page2PersonalDetailsFormStep extends MultiFormStep {
public static $next_steps = 'Page2OrganisationDetailsFormStep';
function getFields() {
return new FieldList(
new TextField('FirstName', 'First name'),
new TextField('Surname', 'Surname')
);
}
}
class Page2OrganisationDetailsFormStep extends MultiFormStep {
public static $is_final_step = true;
function getFields() {
return new FieldList(
new TextField('OrganisationName', 'Organisation Name')
);
}
}
?>