how get values from select form

how get values from select form

by sebastian seitz -
Number of replies: 2

hi,


i created an edit_form.php with an select form.

    $mform->addElement('select', 'config_cid', get_string('allusercourses', 'block_cm_summary'), $allusercourses, $attributes);
    $mform->setDefault('config_cid', 'default value');
    $mform->setType('config_cid', PARAM_TEXT);

How can i get the value of the array?

I tried

print_r($this->config->cid);


but this only prints the index of the array item and not the value.




Average of ratings: -
In reply to sebastian seitz

Re: how get values from select form

by Tomasz Muras -
Picture of Core developers Picture of Plugin developers Picture of Plugins guardians Picture of Translators

Hi,

Where (in what place of your code) do you want to get those values? In other words, where did you put your code

print_r($this->config->cid);


In reply to sebastian seitz

Re: how get values from select form

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

When creating a 'select' form element, the options param ($allusercourses in this case) should be an array of $value => $display.

When you retrieve the saved data, it will be whatever you put in '$value' in the original options.

e.g. if the array was:

3 => Course 1,
6 => Course 2,
8 => Course 3,

And the user selected 'Course 3', then 8 would be returned by the form, to save into the DB.