Moodle advcheckbox for Administrator

Moodle advcheckbox for Administrator

本文关键字:Administrator for advcheckbox Moodle      更新时间:2023-09-26

我在我的面对面mod_form.php中添加了一个advcheckbox表单,在那里我作为管理员可以选中该框,从而允许学生在注册页面中看到租车的一些选项,如果复选框未被管理员标记则隐藏。以下是我在mod_form.php

中的代码
$mform->addElement('advcheckbox', 'allowcarhire',    get_string('facetoface_allowcarhire', 'facetoface'));
    $mform->setDefault('allowcarhire', 0);
    $mform->setType('allowcarhire', PARAM_BOOL);

下面是用户注册表单(signup_form.php)中的代码,它为我们提供了租车的选项:

$mform->addElement('advcheckbox', 'carrequired', get_string('facetoface_carrequired', 'facetoface'));
    $mform->setDefault('carrequired', 0);
    $mform->setType('carrequired', PARAM_BOOL);
    $mform->addElement('date_selector', 'checkin', get_string('facetoface_checkin', 'facetoface'));
    $mform->setType('checkin', PARAM_INT);
    $mform->disabledIf('checkin', 'carrequired', 'notchecked');
    $mform->addElement('date_selector', 'checkout', get_string('facetoface_checkout', 'facetoface'));
    $mform->setType('checkout', PARAM_INT);
    $mform->disabledIf('checkout', 'carrequired', 'notchecked');
    $mform->addElement('advcheckbox', 'minivan', get_string('facetoface_minivan', 'facetoface'));
    $mform->setDefault('minivan', 0);
    $mform->setType('minivan', PARAM_BOOL);

如何连接它们,如果mod_form.php中的第一个复选框未被选中,用户无法在他的注册表单中看到租车选项?可以只与php或我们需要javascript也?

首先,我假设您已经处理了将mod_form中的设置保存到数据库中的问题(我假设您已经向表mdl_facetoface添加了一个名为'allowcarhire'的新字段来保存此设置)。

现在您需要通过'customdata'表单值将该值传递到表单中(查找$params = compact('s',…)行,就在mod/facetoface/sign .php中的$mform = new mod_facetoface_signup_form(null, $params)上方)

进入表单后,假设您在向customdata添加设置时保留了名称'allowcarhire',那么您应该可以这样写:

if ($this->_customdata['allowcarhire']) {
    $mform->addElement('advcheckbox', 'carrequired', ...
}