Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

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.

All other Modules /

Discuss all other Modules here.

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

Multiform module, conditional statements


Go to End


5 Posts   2083 Views

Avatar
Harley

Community Member, 165 Posts

3 March 2010 at 12:25pm

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.

Avatar
Harley

Community Member, 165 Posts

10 March 2010 at 2:30am

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

Avatar
Sean

Forum Moderator, 922 Posts

10 March 2010 at 5:12pm

Where are you putting the echo?

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

Sean

Avatar
Harley

Community Member, 165 Posts

11 March 2010 at 2:00am

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.

Avatar
MightyQ

Community Member, 1 Post

11 February 2013 at 12:04pm

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!