Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

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

(solved) Get Name from selected DropDownList element

Go to End

4 Posts   1393 Views


Community Member, 19 Posts

15 March 2011 at 5:38am

Edited: 15/03/2011 5:40am


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(
return $form;

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


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


Community Member, 344 Posts

15 March 2011 at 6:08am

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];


Community Member, 19 Posts

15 March 2011 at 8:10am

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' >
<% end_control %>

But at the momentan no data are displayed.

Best regards, Beppo


Community Member, 19 Posts

17 March 2011 at 12:34am

Edited: 17/03/2011 12:34am

For my last posting I created a new Thread:

Show data after submitting a form

Thanks for the help.