Why oh why does the form always go to the 'PersonalDetailsFormStep', no matter what the choice of 'AreaChoice' is? See the following for code:
I don't see it...
Thanks!
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Why oh why does the form always go to the 'PersonalDetailsFormStep', no matter what the choice of 'AreaChoice' is? See the following for code:
I don't see it...
Thanks!
Anyone? The multiform module is excellent (and overlooked as I can not find many posts about it in the forum) except for this little problem I have...
Thanks.
Does it call the getNextStep() method at all? a) its not calling that or b) $this->loadData() is not returning anything.
Thanks for your reply, willr.
AFAIK, it seems getNextStep() gets called. Also, the value of AreaChoice is written in the session variable. I very quickly checked loadData() with an echo and that seems OK as well. The thing is, weird things are happening in the if-else statement. It goes to whatever step I define after the 'else' statement...
I believe your problem is because "AreaChoice" is not available until the step is saved. MultiForm::next() will check for what the next step is, before saving the current step's data.
Also, you should probably do your getNextStep() check by checking for AreaCode as an array index, because it's currently a pointer to a property on $this->loadData() e.g.:
public function getNextStep() {
$data = $this->loadData();
if($data['Gender'] == 'Male') {
return 'TestThirdCase1Step';
} else {
return 'TestThirdCase2Step';
}
}
If we have a look at MultiForm.php, specifically the next() method contained in that file:
public function next($data, $form) {
// Get the next step class
$nextStepClass = $this->getCurrentStep()->getNextStep();
if(!$nextStepClass) {
Director::redirectBack();
return false;
}
// custom validation (use MultiFormStep->getValidator() for built-in functionality)
if(!$this->getCurrentStep()->validateStep($data, $form)) {
Director::redirectBack();
return false;
}
// Save the form data for the current step
$this->save($form->getData());
...
I think it's perfectly acceptable to assume you can use the current step data to determine where to go next. The problem is the above code doesn't do that. Ideally, the above code would call $this->save() first, before checking $this->getCurrentStep()->getNextStep()
You could have a go at fixing this by copying the next() method from MultiForm into your subclass for the form you're making, this will override the default behaviour when someone clicks the Next button in the form.
In the mean time, I'll open up a ticket at http://open.silverstripe.com to get this fixed for a future multiform release.
Hope this helps!
Cheers,
Sean
Sean, thanks for your reply! I'll give it a try again, with the suggestions you provided.
Thanks.