Moodle advcheckbox for Administrator

时间:2015-09-09 08:05:21

标签: javascript php moodle

我在面对面的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吗? Moodle中的其他所有内容都是未修改的,并且安装简洁。

1 个答案:

答案 0 :(得分:0)

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

现在您需要通过&#39; customdata&#39;将此值传递到表单中。表单值(查找$ params = compact(&#39; s&#39;,...)行,正好在$ mform = mod / facetoface / signup.php中的新mod_facetoface_signup_form(null,$ params)。< / p>

一旦你进入表格,并假设你保留了名称&#39; allowcarhire&#39;将设置添加到customdata时,您应该能够写:

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