Editor element not displaying saved data

Editor element not displaying saved data

by Andrew Tainton -
Number of replies: 1

I have created a generic form that uses a editor in the form. I am able to save to the database but when I when try edit the record in the form the editor element only displays the default and not the record from the database.

I have the following editor element:

$mform->addElement('editor', 'forum_body', 'Forum Body');

$mform->setType('forum_body', PARAM_RAW);

$mform->setDefault('forum_body', array('text' => get_config('local_forum_events', 'defaultproperties_body'),'format' => FORMAT_HTML));

When the page loads I set the following data:

if($id) {

        $dataforform = $DB->get_record('local_forum_events', array('id' => $id));

        if($dataforform) {

          $mform->set_data($dataforform);

        } else {

          throw new dml_exception("A record with id $id does not exist.");

        }

    }


I have done a var_dump on the $mform and i can see my data in the _defaults of the mform array but i am not sure why it doesnt get set.

Average of ratings: Useful (1)
In reply to Andrew Tainton

Re: Editor element not displaying saved data

by Enrico Preti -

You can't put a simple string in $dataforform->forum_body if you want use set_data.

Try something like this:

$dataforform->forum_body = array('text'=>'text to put in the editor');

or use file_prepare_standard_editor function.




Average of ratings: Useful (1)