Hello
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');
}else{
return array('No Tours found');
}
}
class Tour_Controller extends Page_Controller {
function BookingsForm() {
$fields = new FieldSet(
new DropdownField(
'TourProgram',
'Select a trip',
$this->getMyTours()
),
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?