У меня проблема с TinyMCE, когда я отправляю контент в базу данных, он сохраняется с <!doctype...<html>.....<body>
. Я видел несколько сообщений об удалении полностраничного плагина, но в моем случае у меня его нет. Поэтому я попытался удалить его, чтобы быть уверенным, и обновить кеш браузера, и у меня все еще была та же проблема. Я просто хочу сохранить HTML-код между тегами body.
Я отправляю tinyMCE как обычную форму с текстовой областью, имеющей имя POST и с кнопкой отправки.
<form method="post" action="/profile/edit/profile/text">
{{ csrf_field() }}
<input type="hidden" name="text2" value="1">
<textarea id="tinymce-editor" name="text">{!! $profile -> text !!}</textarea>
<button class="btn btn-success" type="submit"><i class="fa fa-fw fa-check"></i>Lagre</button>
</form>
.
/**
* @return mixed
*
* Process profile text
*/
public function postEditText() {
// Sanitize HTML
$html = $this -> sanitizeHTML(Input::get('text'));
// Validate
$val = Validator::make([
'text' => $html
], [
'text' => 'sometimes|max:50000'
]);
if ($val -> fails()) {
return $this -> backWithErrors($val);
}
// Update
Auth::user() -> profile() -> update([
'text' => $html
]);
return $this -> backWithSuccess('Profilteksten ble lagret!');
}
.
/**
* @param $html
* @return string
*
* HTML sanitizer
*/
private function sanitizeHTML($html) {
// Disable entity loader
libxml_disable_entity_loader(false);
// New DOM doc
$d = new \DOMDocument();
$d -> loadHTML($html);
// Script tags
$st = $d -> getElementsByTagName('script');
$l = $st -> length;
// Remove
for ($i = 0; $i < $l; $i++) {
$st -> item($i) -> parentNode -> removeChild($st -> item($i));
}
return $d -> saveHTML();
}
Заранее спасибо.