Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Getting the selected value of an OptionsetField

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

Page: 1
Go to End
Author Topic: 1705 Views
  • Patrick__
    Avatar
    Community Member
    8 Posts

    Getting the selected value of an OptionsetField Link to this post

    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

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Getting the selected value of an OptionsetField Link to this post

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

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