Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

761 Posts in 242 Topics by 250 members

Form Questions

SilverStripe Forums » Form Questions » Set default value for OptionsetField

Page: 1
Go to End
Author Topic: Set default value for OptionsetField 404 Views
  • Ben_W
    avatar
    Community Member
    42 posts

    Set default value for OptionsetField Link to this post

    I have the following code in one of my forms for the backend cms, it seems that $source will only take numeric array, not associative array.
    original code:
    $myMediaType = new OptionsetField(
                       $name = "MediaType",
                       $title = "Media Type",
                       $source = array(
                          "Video" => "Video",
                          "Audio" => "Audio"
                       ),
                       $value = "Video"
                      );
          $fields->addFieldToTab('Root.Content.Main', $myMediaType, 'Content');   

    this will not work, but if I change the $source to a numeric array, it will set the default value.

    $myMediaType = new OptionsetField(
                       $name = "MediaType",
                       $title = "Media Type",
                       $source = array("Video", "Audio"),
                       $value = 0
                      );
          $fields->addFieldToTab('Root.Content.Main', $myMediaType, 'Content');

    Does anyone come cross this problem, I would prefer to store string 'Video', 'Audio' into the database rather than integer. Could someone please point me the right direction? Thank you!

    404 Views
Page: 1
Go to Top

Currently Online: There is nobody online.

Welcome to our latest member: Bogie

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

Comments on this website? Please give feedback.