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!

Comments

  • Can you give an example of a dropdown list you are referring to?
  • Hi meierrom,

    thanks for your reply. :)

    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
    ub123meierrom
  • Thanks Sandra. That helped me a lot!
    admin
Sign In or Register to comment.