如何以 moodle 形式编写锚标记?

How can I write anchor tag in moodle form?

我有一个 moodle 表格。在 form 中,我必须写一个 锚标记 。我的表单如下所示:

function definition() {
    global $DB;
    $mform =&$this->_form;
    $mform->addElement('editor', 'question', 'Question');
    $mform->addRule('question', null, 'required', null, 'client');
    $mform->setType('question', PARAM_RAW);

    //here I want an anchor tag

    $this->add_action_buttons(false, 'SAVE');
}

我想在文本编辑器和表单中的按钮之间写一个anchor tag

我把锚标签写成

echo "<a href='/path/filename.txt' download='filename.txt'>filename.txt</a>";

但这显示在页面顶部。我想要这个 anchor 就在编辑器字段下方。(我可以把位置 absolute/relative,但这会造成一些样式问题并且没有响应)

我在这里使用这个 anchor 标签来下载一些文件。

请帮帮我...我的 moodle 版本是 2.9.1

有两种方法可以将原始 HTML 插入 Moodle 表单,使用 'static' 元素或使用 'html' 元素。

如果您想要标记为 link,则使用 'static' 元素:

$linkcontent = '<a href="/path/filename.txt">filename.txt</a>';
$mform->addElement('static', 'mylink', get_string('mylink', 'myplugin'), $linkcontent);

如果您只想将一些任意 HTML 内容放入表单中:

$linkcontent = '<a href="/path/filename.txt">filename.txt</a>';
$mform->addElement('html', $linkcontent);

注意:'mylink' 只是引用静态元素的任意名称 - 它叫什么并不重要,但最好让它独一无二(我之前遇到过问题当留空或有重复时)。 get_string 部分是按照与其他表单元素相同的方式来标记元素(如果不需要标签,则使用 'html' 版本代替)。