how get values from select form

how get values from select form

napisao/la sebastian seitz -
Broj odgovora: 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.




U odgovoru na sebastian seitz

Re: how get values from select form

napisao/la Tomasz Muras -
Slika Core developers Slika Plugin developers Slika Plugins guardians Slika 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);


U odgovoru na sebastian seitz

Re: how get values from select form

napisao/la Davo Smith -
Slika Core developers Slika Particularly helpful Moodlers Slika Peer reviewers Slika 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.