Php Moodle表单显示假值

Php Moodle表单显示假值,php,mysql,moodle,Php,Mysql,Moodle,在Moodle中的活动模块中,我有advcheckbox,如果用户想将4座车作为一辆车,它会保存下来。看起来是这样的: $mform->addElement('advcheckbox', 'fourseater', get_string('fourseater', 'newmodule')); $mform->setDefault('fourseater', 0); $mform->setType('fourseater', PA

Moodle
中的
活动
模块
中,我有
advcheckbox
,如果用户想将4座车作为一辆车,它会保存下来。看起来是这样的:

        $mform->addElement('advcheckbox', 'fourseater', get_string('fourseater', 'newmodule'));
        $mform->setDefault('fourseater', 0);
        $mform->setType('fourseater', PARAM_BOOL);
这一切都很好,值被正确保存,如果你选中该框,你会在关于工人的信息中得到四人座。然后我想改变形式,这样用户可以选择2座和4座汽车。一个下拉列表,看起来像这样:

$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);
它正确显示,但在数据库中仅保存了
twoseater
。由于我还可以选择将用户记录下载为
.xls
,因此每次只保存
双座车
,不知道我选择了什么。下面是如何将数据提取到
.xls

$data[] = ($workers->fourseater == "1") ? get_string('fourseater', 'newmodule') : get_string('twoseater', 'newmodule');
在数据库中,这是表单的字段(我没有将
fourseater
的名称更改为
caroptions
,因为这没有任何区别):


我做错了什么,在我更改了
表单之后,它停止正常工作了?

你还记得吗

$mform->setType('fourseater', PARAM_BOOL);
应该是

$mform->setType('fourseater', PARAM_INT);

选择的名称也是
caroptions
-我猜它应该是
fourseater

是的,它来自遗忘的
参数。谢谢拉塞尔!
$mform->setType('fourseater', PARAM_INT);