Jump to:

10979 Posts in 2722 Topics by 1815 members

All other Modules

SilverStripe Forums » All other Modules » How to make getNextStep() work in MultiForm?

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2152 Views
  • SilverRay
    Avatar
    Community Member
    167 Posts

    How to make getNextStep() work in MultiForm? Link to this post

    Why oh why does the form always go to the 'PersonalDetailsFormStep', no matter what the choice of 'AreaChoice' is? See the following for code:

    http://pastie.org/575633

    I don't see it...

    Thanks!

  • SilverRay
    Avatar
    Community Member
    167 Posts

    Re: How to make getNextStep() work in MultiForm? Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: How to make getNextStep() work in MultiForm? Link to this post

    Does it call the getNextStep() method at all? a) its not calling that or b) $this->loadData() is not returning anything.

  • SilverRay
    Avatar
    Community Member
    167 Posts

    Re: How to make getNextStep() work in MultiForm? Link to this post

    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...

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: How to make getNextStep() work in MultiForm? Link to this post

    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

  • SilverRay
    Avatar
    Community Member
    167 Posts

    Re: How to make getNextStep() work in MultiForm? Link to this post

    Sean, thanks for your reply! I'll give it a try again, with the suggestions you provided.

    Thanks.

    2152 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.