2020-04-27, 15:41:56
Just FYI:
The Item object method setFieldValue() is used to populate the field value appropriate to its concept.
The method can contain 3 parameters:
(mixed) $field_name - is the name of the field which value should be filled.
(mixed) $field_value - is the field value.
(boolean) $sanitize (optional) - is a flag that can be used to sanitize the passed $field_value according to the field concept. This value is set to "true" by default.
For example, to set a value of the field of type "text" with the name "content", you can use the method as follows:
it echoes: bla-alert("XSS")
Because sanitize flag is set to "true" by default and it removes any HTML.
Another example. If you have set the minimum length of 20 characters for the field content (under IM field details):
This method returns "false" and the value "bla-bla" will not set because it is shorter than 20 characters. To find out why the method does not have the value set you can check the error code:
Here you can get a list of error codes:
https://ehret-studio.com/articles/itemma...ith-items/
If you do not want to sanitize the value, you can set the $sanitize flag to false:
The Item object method setFieldValue() is used to populate the field value appropriate to its concept.
The method can contain 3 parameters:
Code:
setFieldValue($field_name, $field_value[, $sanitize])
(mixed) $field_name - is the name of the field which value should be filled.
(mixed) $field_value - is the field value.
(boolean) $sanitize (optional) - is a flag that can be used to sanitize the passed $field_value according to the field concept. This value is set to "true" by default.
For example, to set a value of the field of type "text" with the name "content", you can use the method as follows:
PHP Code:
$item->setFieldValue('content', 'bla-<script>alert("XSS")</script>');
echo $item->setFieldValue('content');
it echoes: bla-alert("XSS")
Because sanitize flag is set to "true" by default and it removes any HTML.
Another example. If you have set the minimum length of 20 characters for the field content (under IM field details):
PHP Code:
$item->setFieldValue('content', 'bla-bla');
This method returns "false" and the value "bla-bla" will not set because it is shorter than 20 characters. To find out why the method does not have the value set you can check the error code:
PHP Code:
if(!$item->setFieldValue('email', 'bla-bla')) {
echo MsgReporter::errorCode(); // 2 - The length of field value is less than *minimum*
}
Here you can get a list of error codes:
https://ehret-studio.com/articles/itemma...ith-items/
If you do not want to sanitize the value, you can set the $sanitize flag to false:
PHP Code:
if(!$item->setFieldValue('content', '<script>alert("XSS")</script>', false)) {
echo MsgReporter::errorCode();
}
echo $item->getFieldValue('content');