Created
July 16, 2015 11:21
-
-
Save anonymous/ce6188585d5ccaef6982 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyForm1 extends Form { | |
public function __contruct($controller, $name) { | |
$fields = new FieldList([ | |
new TextField('FirstName', _t('MyForm1.FirstName', 'FirstName')), | |
new TextField('LastName', _t('MyForm1.LastName', 'LastName')), | |
]); | |
$actions = new FieldList([ | |
new FormAction('SendMyForm1', _t('MyForm1.SendMyForm1', 'save')), | |
]); | |
$validator = new RequiredFields([ | |
'FirstName', | |
'LastName', | |
]); | |
parent::__construct($controller, $name, $fields, $actions, $validator); | |
} | |
public function SendMyForm1($data) { | |
// do something with the data | |
Debug::log(print_r($data,1)); | |
// redirect to the next step | |
$c = $this->Controller(); | |
return $c->redirect($c->Link('MyForm2')); | |
} | |
} | |
class MyPage extends Page {} | |
class MyPage_Controller extends Page_Controller { | |
private static $allowed_actions = [ | |
'Step1', | |
'Step2', | |
'Step3', | |
'MyForm1', | |
'MyForm2', | |
'MyForm3', | |
]; | |
public function index() { | |
// uses template MyPage.ss and falls back to Page.ss | |
return $this; | |
} | |
public function step1() { | |
// uses template MyPage_step1.ss and falls back to MyPage.ss, Page.ss | |
return $this; | |
} | |
public function step2() { | |
// uses template MyPage_step2.ss and falls back to MyPage.ss, Page.ss | |
// and puts MyForm2 into the template variable $Form, so you could also use MyPage.ss for all steps | |
return $this->customise([ | |
'Form' => $this->MyForm2(), | |
]); | |
} | |
public function MyForm1() { return new MyForm1($this, __FUNCTION__); } | |
public function MyForm2() { return new MyForm2($this, __FUNCTION__); } | |
public function MyForm3() { return new MyForm3($this, __FUNCTION__); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment