Kaizokupuffball Kaizokupuffball - 1 year ago 53
HTML Question

JS TinyMCE is saving full page

I've got this problem with TinyMCE, that when I submit the content to the database, it is saved with

. I saw some posts about removing the fullpage plugin, but in my case, I dont have that. So I tried to delete it to be sure, and refresh my browser cache, and I still got the same problem. I just want to save the HTML in between the body tags.

I submit the tinyMCE like a normal form with the textarea having the POST name and with a submit button.

<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>



* @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

// 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();


Thanks in advance.

Answer Source

You seem to have code that make a new DOMDocument and then loads HTML into it.

If you log the result of Input::get('text') what do you get?

Perhaps your code in sanitizeHTML() is what is creating the complete HTML document?

According to the manual for DOMDocument it "Represents an entire HTML or XML document; serves as the root of the document tree." If that is the case I suspect that is what is creating your entire document - not TinyMCE.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download