JS TinyMCE正在保存整页

时间:2016-07-29 18:53:39

标签: javascript html tinymce

我在使用TinyMCE时遇到了这个问题,当我将内容提交到数据库时,它会与<!doctype...<html>.....<body>一起保存。我看到一些关于删除fullpage插件的帖子,但在我的情况下,我没有。所以我试图删除它以确保,并刷新我的浏览器缓存,我仍然遇到同样的问题。我只是想在身体标签之间保存HTML。

我像普通表单一样提交tinyMCE,其中textarea具有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();

}

提前致谢。

1 个答案:

答案 0 :(得分:1)

您似乎拥有创建新DOMDocument的代码,然后将HTML加载到其中。

如果您记录Input::get('text')的结果,您会得到什么?

也许sanitizeHTML()中的代码是创建完整HTML文档的代码?

根据DOMDocument的手册,它代表整个HTML或XML文档;作为文档树的根。&#34;如果是这种情况,我怀疑这就是创建整个文档的原因 - 而不是TinyMCE。