Jump to:

22977 Posts in 11806 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » How to get the text from dropdownfield

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 788 Views
  • Kerr
    Avatar
    Community Member
    2 Posts

    How to get the text from dropdownfield Link to this post

    Hi Im a new guys learning about silverstripe. as the following code , how can i get the text from dropdownfield, cos I only get the value like 1, 2 ,3,4, thanks .

    ......................

    $titles = DataObject::get('EmailTitle');
    if ($titles){
    $titles = $titles->toDropdownMap('ID','EmailTitle');
    }

    $fields = new FieldSet(
    new TextField('Name','Name*'),
    new EmailField('Email','Email*'),
    new DropdownField('EmailTitle','Title*',$titles),
    new TextareaField('Comments','Comments*')
    );

    ..........

    $mail->Subject = $data['EmailTitle'];

    .........HTML...........

    <select id="Form_ContactForm_EmailTitle" name="EmailTitle">
    <option value="1">About module</option>
    <option value="2">Project</option>
    <option value="3">work</option>
    <option value="4">anything</option>
    </select>

  • JonoM
    Avatar
    Community Member
    103 Posts

    Re: How to get the text from dropdownfield Link to this post

    I think you just change

    $titles = $titles->toDropdownMap('ID','EmailTitle');

    to

    $titles = $titles->toDropdownMap('EmailTitle','EmailTitle');

  • Kerr
    Avatar
    Community Member
    2 Posts

    Re: How to get the text from dropdownfield Link to this post

    yes, it works, thanks JonoM

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