Error: A required parameter (id) was missing when redirect URL in form Moodle
Error: A required parameter (id) was missing when redirect URL in form Moodle
Moodle 3,开发块
我收到以下错误:'A required parameter (id) was missing'。
它发生在 $mform 中,仅当我在重定向($[=26=)的 'Else if' 语句中使用数组('id' => $instance->id)时]).
令人惊讶的是,因为当我在带有重定向的按钮中使用相同的代码时 url,代码工作正常。
我已经尝试了几种方法,但都无济于事。可能是什么问题?
这是一些代码:
$id = required_param('id', PARAM_INT);
$instance = $DB->get_record('block_instances', array('id' => $id), '*', MUST_EXIST);
$context = \context_block::instance($instance->id);
$mform = new newlink();
if ($mform->is_cancelled()) {
$url = new moodle_url('/my');
redirect($url);
} else if ($fromform = $mform->get_data()) {
// data from form
....
$url = new moodle_url('/blocks/name_of_block/links.php', array('id' => $instance->id)); // HERE IS THE PROBLEM
(Note: when I'm using here the block instance id number 123 directly, the redirect is working correct:
$url = new moodle_url('/blocks/name_of_block/links.php?id=123';)
redirect ($url);
} else {
//Set default data (if any)
$mform->set_data($toform);
//displays the form
$mform->display();
}
$url = new moodle_url('/blocks/name_of_block/links.php', array('id' => $instance->id))
echo $OUTPUT->single_button($url, get_string('button:links', 'block_name_of_block')); // THIS IS WORKING CORRECT
是在提交表单时而不是在重定向时?
在你的表格中你有:
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
在上面的代码中你有:
$toform->id = $id;
$mform->set_data($toform);
Moodle 3,开发块
我收到以下错误:'A required parameter (id) was missing'。
它发生在 $mform 中,仅当我在重定向($[=26=)的 'Else if' 语句中使用数组('id' => $instance->id)时]).
令人惊讶的是,因为当我在带有重定向的按钮中使用相同的代码时 url,代码工作正常。
我已经尝试了几种方法,但都无济于事。可能是什么问题?
这是一些代码:
$id = required_param('id', PARAM_INT);
$instance = $DB->get_record('block_instances', array('id' => $id), '*', MUST_EXIST);
$context = \context_block::instance($instance->id);
$mform = new newlink();
if ($mform->is_cancelled()) {
$url = new moodle_url('/my');
redirect($url);
} else if ($fromform = $mform->get_data()) {
// data from form
....
$url = new moodle_url('/blocks/name_of_block/links.php', array('id' => $instance->id)); // HERE IS THE PROBLEM
(Note: when I'm using here the block instance id number 123 directly, the redirect is working correct:
$url = new moodle_url('/blocks/name_of_block/links.php?id=123';)
redirect ($url);
} else {
//Set default data (if any)
$mform->set_data($toform);
//displays the form
$mform->display();
}
$url = new moodle_url('/blocks/name_of_block/links.php', array('id' => $instance->id))
echo $OUTPUT->single_button($url, get_string('button:links', 'block_name_of_block')); // THIS IS WORKING CORRECT
是在提交表单时而不是在重定向时?
在你的表格中你有:
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
在上面的代码中你有:
$toform->id = $id;
$mform->set_data($toform);