2015-12-20 84 views
0

我使用pagedown編輯器替換正在構建的應用程序中的textarea,但是當我從編輯器獲取示例代碼作爲輸入並將其保存在數據庫中時,查詢出結果給出結果沒有任何格式。 我期待的結果與pagedown編輯器的預覽相同。從pagedown編輯器保存數據庫中的輸入

這是形式

    {{Form::open(array('url'=>'profile/askquestion'))}} 
        <div class="form-group"> 
         <label for="inputEmail" class="control-label">Title</label> 
         <div class=""> 
         <input type="text" class="form-control" id="inputEmail" name="title" value="{{ Input::old('title') != NULL ? Input::old('title') : '' }}" placeholder="What's your programming question? Be specific." autofocus> 
         <span class="badge alert-danger">{{ ($errors->has('title') ? $errors->first('title') : '') }}</span> 
         </div> 
        </div> 
        <div class="form-group"> 
         <label for="inputEmail" class="control-label"></label> 
         <div class="wmd-panel1"> 
         <div id="wmd-button-bar-second" class="pagedown-swag"></div> 
         <textarea class="wmd-input form-control" name="body" id="wmd-input-second" rows="10"></textarea> 
         <span class="badge alert-danger">{{ ($errors->has('body') ? $errors->first('body') : '') }}</span> 
         </div><br ><hr> 

         <div id="wmd-preview-second" class="wmd-preview"></div><hr> 
        </div> 
        <div class="form-group"> 
         <div class=""> 
         <button type="submit" class="btn btn-primary pull-right">Post Your Question</button> 
         </div> 
        </div> 
       {{Form::close()}} 

代碼在數據庫中保存

public function postAskquestion(){ 
    $registerData = Input::all(); 
    $registerRules = array(
     'title'  =>'required', 
     'body'  =>'required', 
     ); 
    $registerValidator = Validator::make($registerData,$registerRules); 
    if($registerValidator->fails()) { 
     return Redirect::back()->withInput()->withErrors($registerValidator); 
    } 
    if($registerValidator->passes()) { 
     $question = new Question(); 
     $question->title = Input::get('title'); 
     $question->description = Input::get('body'); 
     $question->user_id = Auth::user()->id; 
     $question->save(); 


     return Redirect::to('/')->with('alertMessage',"question posted successfully."); 
    } 

} 

代碼用於查詢包含

Route::get('question/{id}/{slug}', function ($id, $slug) { 

$data['question'] = Question::find($id); 

    return View::make('site.question')->with($data); 

});用於顯示包含

代碼

<div id="wmd-preview" class="wmd-panel1 wmd-preview">{{$question->description}}</div> 

請幫助

+0

你能發佈一些代碼嗎? –

回答

0

我知道這是舊的文章,但這裏是我正在做它

我從wmd-preview並保存保存HTML它與ajax

jQuery

var value = $("#wmd-preview).html(); 
$.ajax({ 
    type: "POST", 
    url: "path/to-your-php-file", 
    dataType: "html", 
    data: {value: value} //The first value is the variable that you're sending to PHP 
}) 

PHP

CONNECT TO YOUR DATABASE 

$value = $_POST['value]; 
$query = mysqli_query($db,"INSERT INTO posts VALUES('$value')); 
相關問題