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.

General Questions /

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

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

How to get the text from dropdownfield


Go to End


3 Posts   1163 Views

Avatar
Kerr

Community Member, 2 Posts

15 October 2010 at 2:44am

Edited: 15/10/2010 2:45am

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>

Avatar
JonoM

Community Member, 130 Posts

15 October 2010 at 7:01pm

I think you just change

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

Avatar
Kerr

Community Member, 2 Posts

15 October 2010 at 7:38pm

yes, it works, thanks JonoM