首页 > 解决方案 > Moodle 所需参数

问题描述

我无法摆脱此错误页面:

Debug info:
Error code: missingparam

Stack trace:
line 481 of \lib\setuplib.php: moodle_exception thrown
line 548 of \lib\moodlelib.php: call to print_error()
line 31 of \edit_form.php: call to required_param()

编辑.php:

$aroleid = 72; (I could get this value from database)
echo html_writer::div('<a href="'.$CFG->wwwroot.'/edit_form.php?aroleid='.$aroleid.'">'.$org->org_name.'</a>');

编辑表格.php:

 require('config.php');
    require_once($CFG->libdir.'/formslib.php');
    require_once($CFG->libdir.'/adminlib.php');
    $aroleid = required_param('aroleid', PARAM_INT);
    global $DB, $aroleid;
class edit_form extends moodleform 
{    
    function definition()
    {
        global $DB, $aroleid;       
        $mform = $this->_form;  

        $mform->addElement('text', 'roleid');
        $mform->setType('roleid', PARAM_INT);       
        $mform->setDefault('hroleid', $aroleid);

        $this->add_action_buttons();
    }
}

$mform = new edit_form();
if ($mform->is_cancelled()) {
    redirect(new moodle_url('/index.php'));
}                                                                    
else if ($mform->is_submitted()) {
redirect(new moodle_url('/view.php'));

我可以得到参数 aroleid,提交表单时会显示此错误,并且表单不允许重定向到 view.php。我被卡住了,无法追踪到下一个级别的问题。非常感谢您的建议。

标签: moodle

解决方案


当您提交表单时,它包括字段“roleid”和“hroleid”。

默认情况下,表单提交到当前页面,但当前页面在加载时期望有一个名为“aroleid”的参数。

由于您的表单不包含“aroleid”字段,因此您会收到一个错误,指出缺少参数。


推荐阅读