jquery - 尝试使用 Summernote 编辑器将图像 url 保存到数据库时删除了样式属性

标签 jquery codeigniter summernote

我正在使用 Summernote 编辑器将文本和图像保存到数据库。目前我已将 Summernote 嵌入到 Codeigniter 中,因此我将图像文件上传到服务器,然后检索 url 并将图像插入编辑器。现在根据文档,我们可以调整上传到服务器的图像大小,并将 CSS 应用到图像。

插入代码并应用 Css,显示完美结果。注意数据文件名属性正在保存。

 $('#summernote').summernote('insertImage', objFile, function ($image) {
                        $image.css('width', $image.width() / 3);
                        $image.attr('data-filename', 'retriever');
                    });

一切都很好,除了当我提交表单时,样式属性从 img 标签中删除并且其余数据被保存。

我的 Controller 功能,我将数据保存到数据库。

if($this->input->post())
        {
            var_dump($_POST);
            $this->data=array(
            'PageID'=>$this->input->post('PageID'),
            'Title'=>$this->input->post('Title'),
            'Description'=>$this->input->post('Description'),
            'Text'=>$this->input->post('Text'),
            'CreatedBy' => 1,
            'CreatedDate' => date('Y-m-d'),
            'UpdatedBy' => 1,
            'IsActive' => 1,
            'IsDeleted' => 0
            );

            $Where=array('PageID'=>$this->input->post('PageID'));
            $Result=$this->model->insert('pagedata',$this->data,'ID',$this->input->post('PageID'),$Where);
            if($Result)
            {
                $this->session->set_flashdata('Success',"Page Updated Successfully");
                $Path=previousURL();
                redirect($Path);
            }
            else
            {
                $this->session->set_flashdata('Error',"Sorry Couldnt Update The Page");
                $Path=previousURL();
                redirect($Path);
            }
        }

注意在var_dump中我看到样式属性应用于img,但是当数据到达数据库时样式属性不存在我的问题是style标签在应用于时没有保存在数据库中当我上传图像时,我的意思是说它存在

最佳答案

您面临的问题是由 CodeIgniter 的 XSS 过滤引起的,该过滤会从图像字符串中删除或剥离样式属性,然后将数据传递到数据库。

更改:

$this->input->post('TextAreaName')

$_POST['TextAreaName']

关于jquery - 尝试使用 Summernote 编辑器将图像 url 保存到数据库时删除了样式属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36930219/

相关文章:

php - 在 CodeIgniter 的 Active Record 查询中删除/禁用变量上的反引号

php - 为 View 使用替代结构时出错

jquery - 委托(delegate)事件: selector of many elements

javascript - 如何在jquery中使用多个条件?在 jquery 中同时使用 IF OR

javascript - jQuery/Javascript - 将 div 高度设置为该行中的最大元素高度

mysql - Codeigniter如何在事件记录中进行复杂查询

javascript - Summernote 不会编辑其内容

javascript - Summernote 图片从 URL 上传

angularjs - Angular-Summernote 图像上传编辑器对象未定义