Jump to:

10979 Posts in 2722 Topics by 1815 members

All other Modules

SilverStripe Forums » All other Modules » Multiform module, conditional statements

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1547 Views
  • Harley
    Avatar
    Community Member
    153 Posts

    Multiform module, conditional statements Link to this post

    Hi,

    I've been trying to jump a step in my multi form, please see code below:

    First.php

    <?php

    class First extends DataObject{

       static $db = array (
          'Firststepfield' => 'Text',
          'DropDownOne' => 'Text',
       );

       static $field_labels = array(
          'Firststepfield' => 'First step field',
       );

    public function getFrontendFields(){
       $fields = $this->scaffoldFormFields(array(
          'restrictFields' => array(
             'Firststepfield',
          ),
          'fieldClasses' => array(
             'Firststepfield' => 'TextField',
             )
          )
       );
       
       $FirstChoiceArray = array(
          'OptionOne' => 'Option one' ,
          'OptionTwo' => 'Option two',
          'OptionThree' => 'Option three',
          'OptionFour' => 'Option four'
       );

       $fields->push( new DropdownField( 'DropDownOne', 'Drop down one', $FirstChoiceArray ) );
       return $fields;
       }
    }

    ?>

    FirstStep.php

    <?php

    class FirstStep extends MultiFormStep{
       //protected static $next_steps = 'SecondStep';

       function getFields(){
          $fields = singleton('First')->getFrontEndFields();
          return $fields;
       }

       public function getNextStep(){
          $data = $this->loadData();
          // if self
          if($data['DropDownOne'] == 'OptionThree'){
             return 'ThirdStep';
          } else {
          // if othe than self
             return 'SecondStep';
          }
       }
    }

    ?>

    when I echo $data['DropDownOne']; I'm getting "OptionThreeOptionThree" output to the screen. Any ideas why?

    basically I'm checking for the value "OptionThree" but this has somehow changed to "OptionThreeOptionThree".

    Any help is much appreciated.

  • Harley
    Avatar
    Community Member
    153 Posts

    Re: Multiform module, conditional statements Link to this post

    Bump,

    Really stuck on this, can't figure out why it is happening. The fact that when I echo $data['DropDownOne'] to the screen it is reoccurring almost suggests there is some kind of loop happening but I don't understand this.

    any ideas?

    Regards

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Multiform module, conditional statements Link to this post

    Where are you putting the echo?

    If you var_dump($data) does it produce three arrays?

    Sean

  • Harley
    Avatar
    Community Member
    153 Posts

    Re: Multiform module, conditional statements Link to this post

    Hi Sean,

    I've just been writting the echo in the getNextStep() function.

    If I do the same with the var_dump it writes the same array out twice.

  • MightyQ
    Avatar
    Community Member
    1 Post

    Re: Multiform module, conditional statements Link to this post

    Hey, did you ever resolve this issue? I have a similar problem. Multiform creates two sessions and two steps each time. I see the arrays printed out twice too. Do you know what causes this?

    Please help!

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