我如何在 moodle 表单之外使用 tinymce 编辑器?
How can I use tinymce editor outside moodle form?
如何在 moodle form
之外使用 tinymce editor
?在 moodle form
中,我可以将 editor(tinymce)
用作:
$mform->addElement('editor', 'title', 'Question');
$mform->addRule('title', null, 'required', null, 'client');
$mform->setType('title', PARAM_RAW);
但我想在 moodle form
之外使用 editor field(tinymce)
并获取其中的值。
我该怎么做?请帮助我...
我的 moodle 版本是 2.9.1
这有点尴尬,因为 Moodle 并不真的希望你在它们的形式之外使用这些东西 类。
但你可以这样做:
$editor = \editors_get_preferred_editor(); // This gets the default editor for your site
$editor->use_editor("someidhere"); // This is used to set the id of the html element
// This creates the html element
echo \html_writer::tag('textarea', 'somedefaultvalue',
array('id' => "someidhere", 'name' => 'somenamehere', 'rows' => 5, 'cols' => 10));
这将回显带有 "id"、"name" 等的 textarea 元素...您设置并应将富文本编辑器应用于该元素。要从中获取价值,您只需将其视为普通表单元素,因此如果您通过 POST 请求或其他方式提交它,您只需通过它的 "name".[= 来引用它。 12=]
这是一个非常基本的脚本示例,它创建该元素并在您提交表单时向您显示内容:
<?php
require_once '../../config.php';
require_once $CFG->dirroot.'/lib/form/editor.php';
require_once $CFG->dirroot . '/lib/editorlib.php';
// Set up PAGE
$PAGE->set_context( context_course::instance(1) );
$PAGE->set_url($CFG->wwwroot . '/test.php');
$PAGE->set_title( 'title');
$PAGE->set_heading( 'heading' );
echo $OUTPUT->header();
var_dump($_POST);
$editor = \editors_get_preferred_editor();
$editor->use_editor("someid");
echo "<form method='post'>";
echo \html_writer::tag('textarea', 'default',
array('id' => "someid", 'name' => 'somename', 'rows' => 5, 'cols' => 10));
echo "<input type='submit' name='submit' />";
echo "</form>";
echo $PAGE->requires->get_end_code();
如何在 moodle form
之外使用 tinymce editor
?在 moodle form
中,我可以将 editor(tinymce)
用作:
$mform->addElement('editor', 'title', 'Question');
$mform->addRule('title', null, 'required', null, 'client');
$mform->setType('title', PARAM_RAW);
但我想在 moodle form
之外使用 editor field(tinymce)
并获取其中的值。
我该怎么做?请帮助我...
我的 moodle 版本是 2.9.1
这有点尴尬,因为 Moodle 并不真的希望你在它们的形式之外使用这些东西 类。
但你可以这样做:
$editor = \editors_get_preferred_editor(); // This gets the default editor for your site
$editor->use_editor("someidhere"); // This is used to set the id of the html element
// This creates the html element
echo \html_writer::tag('textarea', 'somedefaultvalue',
array('id' => "someidhere", 'name' => 'somenamehere', 'rows' => 5, 'cols' => 10));
这将回显带有 "id"、"name" 等的 textarea 元素...您设置并应将富文本编辑器应用于该元素。要从中获取价值,您只需将其视为普通表单元素,因此如果您通过 POST 请求或其他方式提交它,您只需通过它的 "name".[= 来引用它。 12=]
这是一个非常基本的脚本示例,它创建该元素并在您提交表单时向您显示内容:
<?php
require_once '../../config.php';
require_once $CFG->dirroot.'/lib/form/editor.php';
require_once $CFG->dirroot . '/lib/editorlib.php';
// Set up PAGE
$PAGE->set_context( context_course::instance(1) );
$PAGE->set_url($CFG->wwwroot . '/test.php');
$PAGE->set_title( 'title');
$PAGE->set_heading( 'heading' );
echo $OUTPUT->header();
var_dump($_POST);
$editor = \editors_get_preferred_editor();
$editor->use_editor("someid");
echo "<form method='post'>";
echo \html_writer::tag('textarea', 'default',
array('id' => "someid", 'name' => 'somename', 'rows' => 5, 'cols' => 10));
echo "<input type='submit' name='submit' />";
echo "</form>";
echo $PAGE->requires->get_end_code();