quill.js与laravel 5.3论坛网站集成

时间:2016-10-22 17:31:21

标签: javascript forms laravel laravel-5 quill

我正在寻找一种方法将quill.js整合到我的网站中,但是他们提供的支持不存在或者说是泥泞。有人能帮助我吗?

下面是我的代码,所有内容目前都是内联的,以便更容易看到所有内容。我已经设法让quill在页面上运行,我可以使用它来编辑文本,但是当我提交表单时,它不会提交编辑器的值,因为它应该...

编辑器应将其内容传递给隐藏的输入并提交其内容,但是当我提交表单时,输入不会被填充。

如果有人知道我做错了什么,那么我全都是耳朵,如果有人有更好的方法来尝试这个问题那么我再次接受建议(顺便说一下表格目前设置为GET所以我可以很容易地检查一下正在传递,但已编写的控制器处理正在POST的变量。

<div class="row" style="margin-right: 0px; margin-left: 0px;">
<div class="col-md-6 col-md-offset-3">

    <!-- Title and First Post -->
    <div class="jumbotron">

        <form method="get" action="/forum/create_post" id="create_post">
          @if (count($errors))
          <div style="padding: 10px;">
            <div class="container-fluid" style="background-color: white;  padding: 10px;">
            <ul>
                @foreach ($errors->all() as $error)
                  <li>{{ $error }}</li>
                @endforeach
            </ul>
            </div>
          </div>
          @endif
          {{ csrf_field() }}
          <div style="padding: 10px;">
          <div class="container-fluid" style="background-color: white;  padding: 10px;">
          <input name="title" type="hidden">
          <div id="editor-title">{{ old('title') }}</div>
          </div>
        </div>
                <!--<h1><label for="Title">Title</label></h1>
                <input class="form-control" name="title" type="text" placeholder="Your Title Here...">
            <h1><label for="body">Content</label></h1>-->
            <div style="padding: 10px;">
            <div class="container-fluid" style="background-color: white;  padding: 10px;">
            <input name="body" type="hidden">
            <div id="editor-body">{{ old('body') }}</div>
          </div>
        </div>
            <button class="btn btn-primary" type="submit">Save Profile</button>
        </form>
   </div>
  </div>
</div>

<script type="text/javascript">
 var bodyquill = new Quill('#editor-body', {
modules: {
  toolbar: [
    ['bold', 'italic', 'underline'],
    ['link', 'blockquote', 'code-block', 'image'],
    [{ list: 'ordered' }, { list: 'bullet' }]
  ]
},
placeholder: 'Compose an epic post...',
theme: 'snow'
});
var titlequill = new Quill('#editor-title', {
modules: {
},
placeholder: 'Title Here...',
theme: 'bubble'
});

var form = document.querySelector('form');
form.onsubmit = function() {
var title = document.querySelector('input[name=title]');
   title.value = JSON.stringify(titlequill.getContents());

var body = document.querySelector('input[name=body]');
  body.value = JSON.stringify(bodyquill.getContents());

  console.log("Submitted", $(form).serialize(), $(form).serializeArray());
// No back end to actually submit to!
alert('Open the console to see the submit data!')
return false;
};
</script>

谢谢!

1 个答案:

答案 0 :(得分:0)

更新结果我相当厚,我用来将正文插入正文输入的方法与受保护的单词发生冲突,重新编写代码以省略任何此类冲突

相关问题