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.

Form Questions /

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

Getting the selected value of an OptionsetField


Go to End


2 Posts   2689 Views

Avatar
Patrick__

Community Member, 8 Posts

11 September 2009 at 10:50pm

Hello! :-)
What ist the best way to get the selected value of an OptionsetField in the function of an action?

         function switchLanguageForm() {
		$fields = new FieldSet(new OptionsetField($name="chooseLang", 
                                                                                    $title="Sprache wählen", 
                                                                                    $source = array('de_DE' => 'Deutsch', 'en_GB' => 'English')));	
		$actions = new FieldSet(new FormAction('doSwitchLanguage', 'Sprache wechseln'));
		return new Form($this, 'switchLanguageForm', $fields, $actions);
	}

         function doSwitchLanguage($data, $form) {
           //Here i want to know which language was selected
           //How can this be done?     
         }

I searched for a solution in the documentation, but found nothing. Did i miss something?

Thanks Patrick

Avatar
Hamish

Community Member, 712 Posts

12 September 2009 at 9:24am

function doSwitchLanguage($data, $form) { 
	$lang = $data["chooseLang"]; // de_DE, en_GB etc...
	... rest of code
}