Hi,
I'd like to add a text editor (apart from the intro, which is easy to add by using the add_intro_editor() function) in the moodle form (mod_form.php) of my activity. When an instance of that activity is added and a user visualizes it, the view.php would show the content stored there when the instance was created.
The instructions from here, explain:
editor
There are two ways of using the editor element in code, the first one is easier but expects some standardized fields.
Simple use
- name database fields: textfield, textfieldformat (and textfieldtrust if required)
- create options array. note that context is the best, most local context you have available.
$textfieldoptions = array('trusttext'=>true, 'subdirs'=>true, 'maxfiles'=>$maxfiles,
'maxbytes'=>$maxbytes, 'context'=>$context); - add editor textfield_editorto moodle form, pass options through custom data in form constructor, set $data->id to null if data not exist yet
$mform->addElement('editor', 'textfield_editor', get_string('fieldname', 'somemodule'),
null, $textfieldoptions); - prepare data
$data = file_prepare_standard_editor($data, 'textfield', $textfieldoptions, $context,
'mod_somemodule', 'somearea', $data->id); - get submitted data and after inserting/updating of data
$data = file_postupdate_standard_editor($data, 'textfield', $textfieldoptions, $context,
'mod_somemodule', 'somearea', $data->id);
I had no problem following steps 1 to 3. That is already done.
However, Im stucked in steps 4 and 5.
Where should I put that code? Inside the mod_form.php? Does it have to be inside a particular function (like validation(), data_preprocessing()...)?
What's the "data" variable and where do I get it from?
Some help would be realy, really appreciated. Im totally lost here