General developer forum

mform not picking up variable in editor element

 
Picture of Nikki Macfarlane
mform not picking up variable in editor element
 

I have a custom form with an editor element for a "Description" field. The editor should default to the description already stored on the database. In my form file, I read the database and save the description to a variable called $description. In the file that calls the form, I set the variable as follows:

$mform = new statementForm_form(null, array('description'=>$description));

In the form file, I then call the $description variable in $mform as follows:

$desc=$this->_customdata['description']
$mform->addElement('editor', 'description', 'Course Description');
$mform->setType('description', PARAM_RAW);
$mform->setDefault('description', array('text'=>$desc));

I can get it to work and display if use the words "Default Text" instead of the $desc variable on the default line but I want it to display the actual data from the database.

Can anyone tell me what I am missing?

Thanks,

Nikki

 
Average of ratings: -
Picture of Nikki Macfarlane
Re: mform not picking up variable in editor element
 

I know I have to set the context, but since this is a custom form and the data I want is held in mdl_local_courses (fieldname=description) does anyone have any idea what the context should be?

Thanks

Nikki

 
Average of ratings: -