Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在变量中获取加法值?_Php_Moodle_Quickform - Fatal编程技术网

Php 如何在变量中获取加法值?

Php 如何在变量中获取加法值?,php,moodle,quickform,Php,Moodle,Quickform,moodle php中是否有将username值带入变量的选项 我只想在加载表单时将用户名放入$myUser $mform->addElement('text', 'username', get_string('forumname', 'forum'), $attributes); 参考:-从您的表单外部: $form = new my_form(); $currentdata = (object)array('username' => $user->username); $

moodle php中是否有将
username
值带入变量的选项

我只想在加载表单时将用户名放入
$myUser

$mform->addElement('text', 'username', get_string('forumname', 'forum'), $attributes);

参考:-

从您的表单外部:

$form = new my_form();
$currentdata = (object)array('username' => $user->username);
$form->set_data($currentdata);
$username = $this->_customdata['username'];
$mform->addElement('text', 'username', get_string('forumname', 'forum'), $attributes);
$mform->setDefault('username', $username);
在极少数情况下,您可以使用customdata将其传入:

$form = new my_form(null, array('username' => $user->username));
然后,在您的表单中:

$form = new my_form();
$currentdata = (object)array('username' => $user->username);
$form->set_data($currentdata);
$username = $this->_customdata['username'];
$mform->addElement('text', 'username', get_string('forumname', 'forum'), $attributes);
$mform->setDefault('username', $username);

我不知道该建议什么,我每天都使用moodle表单,我上面所描述的一直对我有用。也许如果你在这里或moodle.org上发布更多的代码,那么有人可能会指出你哪里出了问题。一旦你有了$myuser,你需要用它做什么?@Russell England我需要
onkeyup($myuser)的值javaScript。我猜您应该在表单中使用YUI模块-