Jump to:

23550 Posts in 19336 Topics by 2890 members

General Questions

SilverStripe Forums » General Questions » Dependant dropdown menu's (Forms)

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: 525 Views
  • borriej
    Community Member
    267 Posts

    Dependant dropdown menu's (Forms) Link to this post


    How do you make a dependant dropdown menu on a Form?

    i have a bookingsform:
    - first dropdown menu returns a DataObject. Titles of pages can be selected.
    - Now a secondary dropdown menu must be filled with possible dates/prices, which are stored in the DataObject 'DatesPrices'

    How do i do this?

    my first dropdown is generated by:

    class Tour_Controller extends Page_Controller {

       public function getMyTours(){
          $today = date('Y-m-d');
          if($Pages = DataObject::get("Tour", "EndDate >= '$today'","StartDate", "", "" )){
             return $Pages->map('Title', 'Title', 'Please Select');
             return array('No Tours found');

    class Tour_Controller extends Page_Controller {

       function BookingsForm() {
          $fields = new FieldSet(
             new DropdownField(
                'Select a trip',

    Dates and prices are stored in:

    class DatesPrice extends DataObject {
       public static $db = array(
          'Periode' => 'Text',
          'Price' => 'Int',
          'Comment' => 'Text',
          'SingleSupplement' => 'Int',
          'Description' => 'HTMLText',
       public static $has_one = array (
          'Tour' => 'Tour'
       public function getCMSFields_forPopup() {
          $fields = new FieldSet();
          $fields->push(new TextField('Periode'));
          $fields->push(new TextField('Price'));
          $fields->push(new TextField('Comment'));
          $fields->push(new TextField('SingleSupplement'));
          $fields->push(new SimpleTinyMCEField('Description'));
          return $fields;

    i need the second form to check which value is selected on the first dropdown.. and then use that as some kind of filter on dataobject DatesPrices, but how?

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.