Jump to:

2012 Posts in 1438 Topics by 621 members

Form Questions

SilverStripe Forums » Form Questions » (solved) Get Name from selected DropDownList element

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

Page: 1
Go to End
Author Topic: 933 Views
  • Beppo98
    Avatar
    Community Member
    19 Posts

    (solved) Get Name from selected DropDownList element Link to this post

    Hello,

    I have another question which is - i think so - a very easy question.

    Here is my code for creating a form:

    function Form() {
    $SkripteAll = SkriptHelper::GetSkripte()->toDropdownMap('ID', 'Name');
          
    $fields = new FieldSet(
    new DropdownField('Skript','', $SkripteAll)
    );

    $actions = new FieldSet(
    new FormAction('doSubmit', 'Anzeigen')
    );

    $form = new Form(
    $this,
    'Form',
    $fields,
    $actions,
    null
    );
    return $form;
    }

    Now I want to know in the doSubmit method, which item the user has selected.
    With

    $data['Skript']


    in the doSubmit method I get the ID (for example 1). But I want to know the name or much better I want to know the complete Skript-object, which I have mapped from the database into the dropdownfield.

    Can anyone help me with my problem?

    Best regards Beppo

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: (solved) Get Name from selected DropDownList element Link to this post

    public $SkripteAll;
    function Form() {
    $this->SkripteAll = SkriptHelper::GetSkripte()->toDropdownMap('ID', 'Name');
    }
    function doSubmit($data,$form) {
    $SkriptID = (int)$data['Skript'];
    if( !empty($this->SkripteAll[$SkriptID]) ) $selectedSkript = $this->SkripteAll[$SkriptID];
    }

  • Beppo98
    Avatar
    Community Member
    19 Posts

    Re: (solved) Get Name from selected DropDownList element Link to this post

    Thanks for your answer, now it works.

    But I have another problem you perhaps could help me. Currently I have one dropdownfield and a button in my form. Depending on the chosen element in the dropdownfield I want to display different data in the frontend page.

    At the moment I tried it to solve in this way:

    public $SkriptanmeldungenAll;

    function doSubmitDruckliste($data, $form) {
    //some code
    $this->SkriptanmeldungenAll = DataObject::get("Skriptanmeldung","SkriptID = '$SkriptID'");
    //...
    }

    function GetSkriptanmeldungen($SkriptID)
    {
    return $this->SkriptanmeldungenAll;
    }

    An the template looks like this:

    ...
    <% control GetSkriptanmeldungen %>
    <tr style='height:30px' >
    <td>$Nachname</td>
    <td>$Vorname</td>
    <td></td>   
    </tr>
    <% end_control %>

    But at the momentan no data are displayed.

    Best regards, Beppo

  • Beppo98
    Avatar
    Community Member
    19 Posts

    Re: (solved) Get Name from selected DropDownList element Link to this post

    For my last posting I created a new Thread:

    Show data after submitting a form

    Thanks for the help.

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