In an activity
module
in Moodle
, I had advcheckbox
, which saved, if the user wants to have 4 seater as a car. It looked like this:
$mform->addElement('advcheckbox', 'fourseater', get_string('fourseater', 'newmodule'));
$mform->setDefault('fourseater', 0);
$mform->setType('fourseater', PARAM_BOOL);
It all worked fine, the value was correctly saved, if you check the box, you get fourseater in the info about the workers. Then I wanted to change the form, so the user can choose between 2 and 4 seater car. A dropdown, that looks like that:
$caroptions = array(
0 => get_string('selectcar', 'newmodule'),
1 => get_string('twoseater', 'newmodule'),
3 => get_string('fourseater', 'newmodule'),
);
$mform->addElement('select', 'caroptions', get_string('caroptions', 'newmodule'), $caroptions);
$mform->setDefault('caroptions', 0);
It is correctly displayed, but in the database is saved only the twoseater
. As I have also option to download the users records as .xls
there is also every time saved only the twoseater
, no mather what I choose. Here is, how the data is being extracted to .xls
:
$data[] = ($workers->fourseater == "1") ? get_string('fourseater', 'newmodule') : get_string('twoseater', 'newmodule');
In the database, this is the field for the form (I didn't change the name of the fourseater
to caroptions
, as it didn't make any difference):
<FIELD NAME="fourseater" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
What I am doing wrong, that after I changed the form
it stoped working correctly?