我正在尝试将所选项目从一个表格移动到另一个表格并收到此错误:
缺少必需参数(id)
$objs = array();
$objs[0] =& $mform->createElement('select', 'choosedepartments', get_string('Choose', 'dlist'), $table, $choices, 'size="25"');
$objs[0]->setMultiple(true);
$objs[1] =& $mform->createElement('select', "selecteddepartments", get_string('Select', 'dlist'), $schoices, 'size="15"');
$objs[1]->setMultiple(true);
$grp =& $mform->addElement('group', 'departmentgrp', get_string('Department list', 'dlist'), $objs, ' ', false);
//$objs[] =& $mform->addElement('submit', 'select', "Select");
$objs = array();
$objs[] =& $mform->createElement('submit', 'addsel', get_string('addsel', 'dlist'));
$objs[] =& $mform->createElement('submit', 'removesel', get_string('removesel', 'dlist'));
$objs[] =& $mform->createElement('submit', 'addall', get_string('addall', 'dlist'));
$objs[] =& $mform->createElement('submit', 'removeall', get_string('removeall', 'dlist'));
$grp =& $mform->addElement('group', 'buttonsgrp', get_string('selectedlist', 'dlist'), $objs, array(' ', '<br />'), false);
答案 0 :(得分:0)
为什么所有&#39; =&amp;&#39;行呢?除非您使用PHP 4(它与Moodle的最新版本不兼容),否则所有对象都会在没有它的情况下通过引用传递。
目前还不完全清楚调用此表单的代码是什么,但我认为显示表单的页面有一行&#39; required_param(&#39; id&#39;,PARAM_INT);&# 39;在它的某个地方。要解决此问题,您需要在表单中添加名为&#39; id&#39;:
的元素$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
无论是初始化表单的代码,还需要使用&#39; setData&#39;为&#39; id&#39;传递正确的值。
e.g。
$id = required_param('id', PARAM_INT); // Something like this line should already exist in the code.
...
$form = new my_form(); // Something like this line should already exist in the code.
...
$form->setData(array('id' => $id));
之后,应该按照惯例&#39; if($ form-&gt; isCancelled())&#39;,&#39; if($ data = $ form-&gt; getData())&# 39;和&#39; $ form-&gt; display()&#39;代码。