silverstripe-frameworktest/code/multiform/Page3MultiForm.php

94 lines
3.0 KiB
PHP
Raw Permalink Normal View History

2010-03-10 21:20:44 +01:00
<?php
use SilverStripe\ORM\DataObject;
2016-07-20 00:34:52 +02:00
use SilverStripe\Security\Member;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
2015-12-17 21:20:49 +01:00
class Page3MultiForm extends MultiForm
{
public static $start_step = 'Page3StartFormStep';
2016-07-20 00:34:52 +02:00
2015-12-17 21:20:49 +01:00
public function finish($data, $form)
{
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 == 'Page3PersonalDetailsFormStep') {
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 == 'Page3OrganisationDetailsFormStep') {
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();
}
}
// Debug::show($step->loadData()); // Shows the step data (unserialized by loadData)
}
}
$controller = $this->getController();
$controller->redirect($controller->Link() . 'finished');
}
2010-03-10 21:20:44 +01:00
}
2015-12-17 21:20:49 +01:00
class Page3StartFormStep extends MultiFormStep
{
2016-07-20 00:34:52 +02:00
2015-12-17 21:20:49 +01:00
public static $next_steps = 'Page3PersonalDetailsFormStep';
2016-07-20 00:34:52 +02:00
2015-12-17 21:20:49 +01:00
public function getFields()
{
return new FieldList(
new LiteralField('Details', '<b>This is important</b><br />
2010-03-10 21:20:44 +01:00
<p>You will receiving email once you participate in this survey. <br />
Under the new Unsolicited Electronic Messages Act 2007, we must have your consent to send emails relating to this form. <br />
If you do not wish to receive these emails please use the unsubscribe checkbox at bottom of this form. <br />
If you still wish to receive these emails, you do not have to do anything.</p><br />
<p>For more information visit <a href=\"http://silverstripe.com\">http://www.silverstripe.com/</a></p>'),
2015-12-17 21:20:49 +01:00
new CheckboxField('Unsubscribe', 'Tick that you confirm the above details.')
);
}
2010-03-10 21:20:44 +01:00
}
2015-12-17 21:20:49 +01:00
class Page3PersonalDetailsFormStep extends MultiFormStep
{
2016-07-20 00:34:52 +02:00
2015-12-17 21:20:49 +01:00
public static $next_steps = 'Page3OrganisationDetailsFormStep';
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 Page3OrganisationDetailsFormStep 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
}