我想将summernote(summernote.org)整合到textarea中并保存在数据库中。
我的观看代码:
<div class="col-lg-3"><label>Estado</label>
<textarea name="textfield4" id="textfield4"></textarea></div>
<button type="submit" class="btn btn-success">Save</button>
<input type="hidden" value="{{Session::token()}}" name="_token">
我的js代码:
<script>
$('#textfield4').summernote({
height:200
});
</script>
答案 0 :(得分:2)
在提交表单之前,您必须使用div来渲染夏天并使用夏季音符内容填充隐藏文本区域,请参阅下面的示例,
<div class="panel-body no-padding">
<textarea style="display: none;" name="emailmessage" id="emailmessage"></textarea>
<div class="editor-summernote" id="emailmessage_editor"></div>
</div>
然后将div转换为渲染夏季音符编辑器,如下所示
$('.editor-summernote').summernote({
toolbar: [
['headline', ['style']],
['style', ['bold', 'italic', 'underline', 'superscript', 'subscript', 'strikethrough', 'clear']],
['textsize', ['fontsize']],
['alignment', ['ul', 'ol', 'paragraph', 'lineheight']],
],
height: 120
});
在提交表单进行服务器端处理之前,使用jquery将夏天音符内容填充到隐藏文本区域,
$("#btn-send-message").on("click",function(event) {
var email_body = $('#emailmessage_editor').code();
$("#emailmessage").html(email_body); //populate text area
});
最后,您可以通过$request->input('emailmessage')
答案 1 :(得分:2)
请告诉我错误消息是什么,如果它不起作用,我修改了您的javascript代码,用实际的表单ID替换yourformid并尝试,我假设你有一个在html中定义了动作的表单,
$(function(){
$('#estado').summernote(
{
toolbar: [
['headline', ['style']],
['style', ['bold', 'italic', 'underline', 'superscript', 'subscript', 'strikethrough', 'clear']],
['textsize', ['fontsize']],
['alignment', ['ul', 'ol', 'paragraph', 'lineheight']],
],
height:120
});
$("#yourformid").submit(function(e) {
var self = this;
e.preventDefault();
var estado = $('#estado').code();
$("#textfield4").html(estado); //populate text area
self.submit();
return false;
});
});
确保您的令牌被传递或使用以下方法生成令牌
<input type="hidden" name="_token" value="{{ csrf_token()
答案 2 :(得分:1)
您应该在.ready()函数
中编写代码$(document).ready(function() {
$('#textfield4').summernote();
});