mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 11:06:02 +02:00
added page2 and page3 multiform tests
This commit is contained in:
parent
b7436e5d5a
commit
76bcf565f3
64
code/Page2MultiForm.php
Normal file
64
code/Page2MultiForm.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
class Page2MultiForm extends MultiForm {
|
||||
|
||||
protected 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 {
|
||||
|
||||
protected static $next_steps = 'Page2OrganisationDetailsFormStep';
|
||||
|
||||
function getFields() {
|
||||
return new FieldSet(
|
||||
new TextField('FirstName', 'First name'),
|
||||
new TextField('Surname', 'Surname')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Page2OrganisationDetailsFormStep extends MultiFormStep {
|
||||
|
||||
protected static $is_final_step = true;
|
||||
|
||||
function getFields() {
|
||||
return new FieldSet(
|
||||
new TextField('OrganisationName', 'Organisation Name')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
28
code/Page2MultiFormTestPage.php
Normal file
28
code/Page2MultiFormTestPage.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
class Page2MultiFormTestPage extends Page {
|
||||
|
||||
static $db = array(
|
||||
);
|
||||
|
||||
static $has_one = array(
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
class Page2MultiFormTestPage_Controller extends Page_Controller {
|
||||
|
||||
function Page2MultiForm() {
|
||||
return new Page2MultiForm($this, 'Page2MultiForm');
|
||||
}
|
||||
|
||||
function finished() {
|
||||
return array(
|
||||
'Title' => 'Thank you for your submission',
|
||||
'Content' => '<p>You have successfully submitted the form. Thanks!</p>'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
85
code/Page3MultiForm.php
Normal file
85
code/Page3MultiForm.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
class Page3MultiForm extends MultiForm {
|
||||
|
||||
protected static $start_step = 'Page3StartFormStep';
|
||||
|
||||
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 == 'Page3PersonalDetailsFormStep') {
|
||||
$member = new Member();
|
||||
$data = $step->loadData();
|
||||
if($data) {
|
||||
$member->update($data);
|
||||
$member->write();
|
||||
}
|
||||
}
|
||||
|
||||
if($step->class == 'Page3OrganisationDetailsFormStep') {
|
||||
$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 Page3StartFormStep extends MultiFormStep {
|
||||
|
||||
protected static $next_steps = 'Page3PersonalDetailsFormStep';
|
||||
|
||||
function getFields() {
|
||||
return new FieldSet(
|
||||
new LiteralField('Details', '<b>This is important</b><br />
|
||||
<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>'),
|
||||
new CheckboxField('Unsubscribe', 'Tick that you confirm the above details.')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Page3PersonalDetailsFormStep extends MultiFormStep {
|
||||
|
||||
protected static $next_steps = 'Page3OrganisationDetailsFormStep';
|
||||
|
||||
function getFields() {
|
||||
return new FieldSet(
|
||||
new TextField('FirstName', 'First name'),
|
||||
new TextField('Surname', 'Surname')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class Page3OrganisationDetailsFormStep extends MultiFormStep {
|
||||
|
||||
protected static $is_final_step = true;
|
||||
|
||||
function getFields() {
|
||||
return new FieldSet(
|
||||
new TextField('OrganisationName', 'Organisation Name')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
28
code/Page3MultiFormTestPage.php
Normal file
28
code/Page3MultiFormTestPage.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
class Page3MultiFormTestPage extends Page {
|
||||
|
||||
static $db = array(
|
||||
);
|
||||
|
||||
static $has_one = array(
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
class Page3MultiFormTestPage_Controller extends Page_Controller {
|
||||
|
||||
function Page3MultiForm() {
|
||||
return new Page3MultiForm($this, 'Page3MultiForm');
|
||||
}
|
||||
|
||||
function finished() {
|
||||
return array(
|
||||
'Title' => 'Thank you for your submission',
|
||||
'Content' => '<p>You have successfully submitted the form. Thanks!</p>'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user