老师,您好,我用tp6框架引入wangeditor,但是无法把编辑内容的值传给后端,能帮忙分析下吗?
html:
<form class="form-horizontal" role="form" enctype="multipart/form-data" method="post" action="/index.php/admin/article/artadd"> <div class="form-group"> <label for="title" class="col-sm-2 control-label">标题</label> <div class="col-sm-10"> <input type="text" class="form-control" id="title" name="title" placeholder="请输入标题" > </div> </div>
<div id="editor—wrapper" name="content"> <div id="toolbar-container" ><!-- 工具栏 --></div> <div id="editor-container" > <!-- 编辑器 --></div> </div> <div class="col-md-2 col-md-offset-9"> <button type="submit" class="btn btn-default" style="float: right;" onclick="save();">保存</button> </div> </form>
js代码
function save(){ var data = new Object; data.content = editor.getHtml(); // if (content =='') {} $.post('/index.php/admin/article/artadd',data,function(res){ },'json'); alert(data.content); }
后端代码
public function artadd(){ //加个判断,让两个不同时执行 if (Request::isPost()) { $title = input('post.title'); $cid = input('post.cid'); $time = time(); $content = htmlspecialchars(input('post.content')); var_dump(input('content')); $status = input('post.status'); $hot = input('post.hot'); $himg = input('post.himg'); $cimg = input('post.cimg'); // $picurl = input('post.picurl'); // 获取表单上传文件 例如上传了001.jpg $file = request()->file('picurl'); // if(!empty($file)){ $savename = \think\facade\Filesystem::putFile( 'topic', $file); // }else{ // echo json_encode(['code'=>0,'msg'=>'上传图片失败']); // } $insert = Db::table('yzt_article')->insert([ 'title' => $title, 'cid' => $cid, 'content' =>$content, 'hot' => $hot, 'himg' => $himg, 'cimg' => $cimg, 'picurl' => $savename, 'status'=>$status, 'time' =>$time ]);
network中看一下请求