Hello,
I'm having a problem with a select box and inserting into the database. So, I created my own moodle form which has got several textbox, selectbox and radio buttons.
When I enter to my form and fill in all fields, press the button 'Save' I'm getting an error with inserting into the table. I understood what the problem is, but I can't find a way to solve it.
I have a select box showing the days - from Monday to Saturday. I created it using the following code:
$arrDays = block_presence_get_days();
$mform->addElement('select', 'selDay', get_string('day:', 'block_presence'), $arrDays);
$mform->addRule('selDay', null, 'required', null, 'client');
where the function block_presence_get_days() is the following one:
function block_presence_get_days() {
return array(get_string('chday', 'block_presence'), //Choose a day
get_string('mon', 'block_presence'), //Monday
get_string('tue', 'block_presence'), //Tuesday
get_string('wed', 'block_presence'), //Wednesday
get_string('thu', 'block_presence'), //Thursday
get_string('fri', 'block_presence'), //Friday
get_string('sat', 'block_presence') //Saturday
);
For example I choose Saturday from the select box and I want to save my information via the button 'Save' (to insert a record into a table), but I use the function print_object() to check if the information will be correctly saved. And here is my surprise:
for the field selDay(for example) I have got the NUMBER 6 instead of the string Saturday. And my big question is why? I cannot understand how that happens. What I want is to have for [selDay] => Saturday, not the number of the element from the array. (the array starts counting from 0, and the seventh element is with number 6 and value Saturday). Could you please someone help me how to solve this problem? Thank you.