RichtextEditor inserting HTML

Is there a possibility to insert HTML Text and save it unescaped to the db in the RichtextEditor?
7 Replies
hyperion-mx
hyperion-mx2mo ago
// if you are in the Creating step you can use
protected function mutateFormDataBeforeCreate(array $data): array
{
// $data['your_rich_editor_field_name'] = whattever you want to do to the field data
// for example
$data['your_rich_editor_field_name'] = strip_tags($data['your_rich_editor_field_name']);
// strip_tags is a php function, or you can use anything else

return $data;
}
// if you are in the Update step

protected function mutateFormDataBeforeSave(array $data): array
{
// same as above

return $data;
}
// if you are in the Creating step you can use
protected function mutateFormDataBeforeCreate(array $data): array
{
// $data['your_rich_editor_field_name'] = whattever you want to do to the field data
// for example
$data['your_rich_editor_field_name'] = strip_tags($data['your_rich_editor_field_name']);
// strip_tags is a php function, or you can use anything else

return $data;
}
// if you are in the Update step

protected function mutateFormDataBeforeSave(array $data): array
{
// same as above

return $data;
}
igorclauss
igorclaussOP2mo ago
Sorry. I was too imprecise with my explanation. I want to be able to insert HTML content and keep the HTML tags explicitly so that I can embed the content later in the same way.
hyperion-mx
hyperion-mx2mo ago
I think it saves it as html in the data column when using a rich editor so no extra work required login to the database and check it to confirm
hyperion-mx
hyperion-mx2mo ago
here is an example where am using the rich editor as you see it does save the tags
No description
igorclauss
igorclaussOP2mo ago
True that. My point was when I insert HTML I have written elsewhere the RichtextEditor saves it escaped to the database. It wraps it in his own tags tough, as you mentioned.
awcodes
awcodes2mo ago
It’s going through a sanitizer to help protect from xss vulnerabilities. The underlying trix editor could be doing its own sanitizing as well. A lot of rich text editors work that way. If you actually need Freeform html then you’re probably going to have to do a custom field where you have more control over what’s allowed and what isn’t.
igorclauss
igorclaussOP2mo ago
Okay, thank you Adam. That's a solution I can work with.
Want results from more Discord servers?
Add your server