// Description.
$mform->addElement('editor', 'description',
get_string('description', 'tool_lp'), array('rows' => 4));
- $mform->setType('description', PARAM_RAW);
+ $mform->setType('description', PARAM_CLEANHTML);
// ID number.
$mform->addElement('text', 'idnumber', get_string('idnumber', 'tool_lp'), 'maxlength="100"');
$mform->setType('idnumber', PARAM_RAW);
// Description.
$mform->addElement('editor', 'description',
get_string('description', 'tool_lp'), array('rows' => 4));
- $mform->setType('description', PARAM_RAW);
+ $mform->setType('description', PARAM_CLEANHTML);
// ID number.
$mform->addElement('text', 'idnumber', get_string('idnumber', 'tool_lp'), 'maxlength="100"');
$mform->setType('idnumber', PARAM_RAW);
$mform->addRule('name', get_string('maximumchars', '', 100), 'maxlength', 100, 'client');
// Description.
$mform->addElement('editor', 'description', get_string('plandescription', 'tool_lp'), array('rows' => 4));
- $mform->setType('description', PARAM_RAW);
+ $mform->setType('description', PARAM_CLEANHTML);
$mform->addElement('date_time_selector', 'duedate', get_string('duedate', 'tool_lp'), array('optional' => true));
$mform->addHelpButton('duedate', 'duedate', 'tool_lp');
// Description.
$mform->addElement('editor', 'description',
get_string('description', 'tool_lp'), array('rows' => 4));
- $mform->setType('description', PARAM_RAW);
+ $mform->setType('description', PARAM_CLEANHTML);
$mform->addElement('selectyesno', 'visible',
get_string('visible', 'tool_lp'));
$mform->addElement('date_time_selector',
$mform->addRule('name', get_string('maximumchars', '', 100), 'maxlength', 100, 'client');
// Description.
$mform->addElement('editor', 'description', get_string('userevidencedescription', 'tool_lp'), array('rows' => 10));
- $mform->setType('description', PARAM_RAW);
+ $mform->setType('description', PARAM_CLEANHTML);
$mform->addElement('url', 'url', get_string('userevidenceurl', 'tool_lp'), array('size' => '60'), array('usefilepicker' => false));
$mform->setType('url', PARAM_RAW_TRIMMED); // Can not use PARAM_URL, it silently converts bad URLs to ''.
),
'description' => array(
'default' => '',
- 'type' => PARAM_RAW
+ 'type' => PARAM_CLEANHTML
),
'descriptionformat' => array(
'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
'type' => PARAM_RAW
),
'description' => array(
- 'type' => PARAM_RAW,
+ 'type' => PARAM_CLEANHTML,
'default' => ''
),
'descriptionformat' => array(
'type' => PARAM_TEXT,
),
'description' => array(
- 'type' => PARAM_RAW,
+ 'type' => PARAM_CLEANHTML,
'default' => ''
),
'descriptionformat' => array(
),
'description' => array(
'default' => '',
- 'type' => PARAM_RAW,
+ 'type' => PARAM_CLEANHTML,
),
'descriptionformat' => array(
'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
'type' => PARAM_TEXT
),
'description' => array(
- 'type' => PARAM_RAW,
+ 'type' => PARAM_CLEANHTML,
'default' => '',
),
'descriptionformat' => array(
*/
final protected static function get_format_field($definitions, $property) {
$formatproperty = $property . 'format';
- if ($definitions[$property]['type'] == PARAM_RAW && isset($definitions[$formatproperty])
+ if (($definitions[$property]['type'] == PARAM_RAW || $definitions[$property]['type'] == PARAM_CLEANHTML)
+ && isset($definitions[$formatproperty])
&& $definitions[$formatproperty]['type'] == PARAM_INT) {
return $formatproperty;
}
// This is a nested array of more properties.
$thisvalue = self::get_read_structure_from_properties($type, $proprequired, $propdefault);
} else {
- if ($definition['type'] == PARAM_TEXT) {
+ if ($definition['type'] == PARAM_TEXT || $definition['type'] == PARAM_CLEANHTML) {
// PARAM_TEXT always becomes PARAM_RAW because filters may be applied.
$type = PARAM_RAW;
}
$data = $this->get_persistent()->to_record();
$class = static::$persistentclass;
$properties = $class::get_formatted_properties();
+ $allproperties = $class::properties_definition();
foreach ($data as $field => $value) {
- // Convert formatted properties.
+ // Clean data if it is to be displayed in a form.
+ if (isset($allproperties[$field]['type'])) {
+ $data->$field = clean_param($data->$field, $allproperties[$field]['type']);
+ }
+
if (isset($properties[$field])) {
$data->$field = array(
'text' => $data->$field,
$formatted = array();
foreach ($properties as $property => $definition) {
$propertyformat = $property . 'format';
- if ($definition['type'] == PARAM_RAW && array_key_exists($propertyformat, $properties)
+ if (($definition['type'] == PARAM_RAW || $definition['type'] == PARAM_CLEANHTML)
+ && array_key_exists($propertyformat, $properties)
&& $properties[$propertyformat]['type'] == PARAM_INT) {
$formatted[$property] = $propertyformat;
}
// Validate_param() does not like false with PARAM_BOOL, better to convert it to int.
$value = 0;
}
+ if ($definition['type'] === PARAM_CLEANHTML) {
+ // We silently clean for this type. It may introduce changes even to valid data.
+ $value = clean_param($value, PARAM_CLEANHTML);
+ }
validate_param($value, $definition['type'], $definition['null']);
} catch (invalid_parameter_exception $e) {
$errors[$property] = static::get_property_error_message($property);