Hi guys,
I am absolutely new to silverstripe and PHP and try to get the selected data from a dropdownlist. I read some posts but either the answer doesn't work for me or there is no answer at all for some of them...
My problem is to get the ID of the selected data from a dropdownlist. My code looks like this:
function BusinessSearchForm() {
$myDoSet = DataObject::get("CompanyCategory");
if($myDoSet){
$map = $myDoSet->toDropDownMap('ID', 'CompanyCategory');
$fields = new FieldSet (new DropdownField(
'CategoryList', $title = "Please select a Category:", $map));
}
// Create actions
$actions = new FieldSet(
new FormAction('doSearchBusiness', 'Search')
);
return new Form($this, 'BusinessSearchForm', $fields, $actions);
}
function doSearchBusiness($data,$form){
just to try to get the selected ID I tried this:
Session::set('CatID',$data['CategoryList']);
function CatID(){
Session::get('CatID');
}
with the .ss like this
<% control CatID %>
My Category ID is: $CatID
<% end_control %>
I obviously missed something as this doesn't work. Then I tried this:
$CatID = $data['CategoryList'];
with .ss like this: My Category ID is: $CatID
This didn't work either.
What I need is something like
$_POST["CategoryList"] to get the ID and then the sql like
$sql="SELECT * FROM Businesses where MyCategoryID = CatID (selected from dropdownlist)"
Can somebody translate this into silverstripe code for me, please? Or explain me what I did wrong?
According to firefox LiveHTTPHeader the CategoryList comes with the selected ID. I just can't get it...