如何将addElement值添加到变量中?

is there any option in moodle php to take username value in to variable ?

I just wanna take username in to $myUser when the form loading.

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

Reference:- http://docs.moodle.org/dev/lib/formslib.php_Form_Definition#addElement

From outside of your form:

$form = new my_form();
$currentdata = (object)array('username' => $user->username);
$form->set_data($currentdata);

In rare cases where this isn't possible, you can, instead, use customdata to pass it in:

$form = new my_form(null, array('username' => $user->username));

Then, within your form:

$username = $this->_customdata['username'];
$mform->addElement('text', 'username', get_string('forumname', 'forum'), $attributes);
$mform->setDefault('username', $username);