PHP - How to Change Items in a Dropdownlist // How to create a new list

Hi Gibbon-Team, Hi Gibbon-Community,

I am currently changing the ApplicationForm for hidding some fields or creating new ones.
Currently working on applicatopmForm.php and applicationFormProcess.php
(https://ask.gibbonedu.org/discussion/1055/how-to-delete-fields-from-application-forms)

My questions are

  • Where can i change the choosable items in a Dropdownlist. (Cant find the right php-file i guess)
  • Where can i create new Dropdownlists?

Many thanks!

Can you give an example of a dropdown list you are referring to?

Hi meierrom,

thanks for your reply. :slight_smile:

For example:

I want to add a new gender for test purposes. (Screens are in German)
But i dont know how to change the items in that dropdownlist.


Hi ub123,

There are two ways you could change this particular dropdown:

In src/Forms/FormFactory.php there is a createSelectGender() method which defines the gender dropdown system-wide.

You can also change the code in your example from addSelectGender(‘gender’) to addSelect(‘gender’) which makes it a generic select drop-down, and add a fromArray() method to provide the selectable items. The code might look something like this:

`$genderOptions = [
    'F'           => __('Female'),
    'M'           => __('Male'),
    'Other'       => __('Other'),
    'Unspecified' => __('Unspecified'),
    // Add your new options here
];
$row = $form->addRow();
    $row->addLabel('gender', __('Gender'));
    $row->addSelect('gender')->fromArray($genderOptions)->required();`
```


Hope this helps! There is some documentation about the Form class here, which may be handy: https://gist.github.com/SKuipers/3a4de3a323ab9d0969951894c29940ae

Thanks Sandra. That helped me a lot!

thank you sandra that very helpful for me :slight_smile:
شكرا

This just helped me big time, i wanted to limit genders to Male Female only
and it worked like a charm, commenting here for if any one needed this in future, he can find it easily by search.

Hi ub123,

There are two ways you could change this particular dropdown:

In src/Forms/FormFactory.php there is a createSelectGender() method which defines the gender dropdown system-wide.

You can also change the code in your example from addSelectGender(‘gender’) to addSelect(‘gender’) which makes it a generic select drop-down, and add a fromArray() method to provide the selectable items. The code might look something like this:

`$genderOptions = [
    'F'           => __('Female'),
    'M'           => __('Male'),
    'Other'       => __('Other'),
    'Unspecified' => __('Unspecified'),
    // Add your new options here
];
$row = $form->addRow();
    $row->addLabel('gender', __('Gender'));
    $row->addSelect('gender')->fromArray($genderOptions)->required();`
```


Hope this helps! There is some documentation about the Form class here, which may be handy: https://gist.github.com/SKuipers/3a4de3a323ab9d0969951894c29940ae
 
remove gender options edit gender list

Thanks Aziz for sharing your solution! Be sure to track these kinds of changes in a list (or in a GitHub fork if you are familiar with version control), otherwise they will be replaced the next time you update Gibbon.