Jump to:

1975 Posts in 1305 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » retrieving data out of dropdown

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

Page: 1
Go to End
Author Topic: 349 Views
  • KimK
    Avatar
    Community Member
    7 Posts

    retrieving data out of dropdown Link to this post

    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...

    349 Views
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.