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

Getting unique values for dropdown


Go to End


2 Posts   1596 Views

Avatar
sca123

Community Member, 61 Posts

21 September 2009 at 5:41am

I am using two dropdowns in a search function for the blog. So, what I need to do is get the unique values for field x and then turn the results into a dropdown - can anyone help?

Avatar
dalesaurus

Community Member, 283 Posts

23 September 2009 at 2:41pm

The 2 simplest options off the top of my head:

1. Post the form back and have a conditional add of the second form if the first dropdown is set. Psudocode:

// form code
if( isset($data['firstDropDown'] } (
    $fields->push( new DropDownField('secondDropDown','Second: ',array('otherdata')) );
}

// form post function
if( ! isset($data['firstDropDown'] ) {
    Director::redirectBack();
}

2. Use jQuery or something with an Ajax Action button on the first dropdown to create/populate the second dropdown. Docs: http://doc.silverstripe.org/doku.php?id=ajaxformaction