簡體   English   中英

無法在laravel中使用with方法獲取textarea值

[英]cannot get the textarea value using with method in laravel

// post / createPlay

<div id="code">
<h2 >源代碼</h2>
<textarea id="textArea" onkeyup="runCode()" >@if(isset($code)) {{$code}} @endif</textarea>
</div>

<div id="result">
<h2 >顯示效果</h2>
<iframe  src="about:blank" id="iFrame" contentEditable="true" ></iframe>
</div>

</div><!--end of playMain-->   

//頁面形式

<form action="http://localhost/html5lav/public/post/playAction" method="post">
<textarea name="playCode">  
    &lt;!DOCTYPE&gt;
    &lt;html&gt;
    &lt;body&gt;

      &lt;div class="circle red"&gt;&lt;/div&gt;
      &lt;div class="circle green"&gt;&lt;/div&gt;

    &lt;/body&gt;
    &lt;/html&gt;
</textarea> 
<input type="submit" value="submit" />
</form>

// PostController中

public function createPlay(){
    return View::make('frontend.post.play');
}
public function playAction(){ 
  $code = Input::get('playCode');
  return Redirect::route('createPlay')->with('code', $code);
}

//路線

  Route::get('post/createPlay', array(
   'uses' => 'PostController@createPlay',
   'as' => 'createPlay'
  ));

  Route::post('post/playAction', array(
   'uses' => 'PostController@playAction',
   'as' => 'playAction'
  ));

我想做的是從表單頁面獲取textarea值,並通過“ with”方法將“ Input :: get('playCode')”數據傳輸到“ post / createPlay”頁面,以便在“ post” / createPlay”頁面上,我們可以將數據轉移到textarea(其ID為textArea)中,並通過使用js從同一頁面的textarea中再次獲取數據在iframe元素中進行顯示。 但是我嘗試了很多次,但沒有成功。 變量$ code只是空的。

您沒有將任何內容傳遞給視圖。 您需要使用View::make()的第二個參數或使用View的with方法將$code發送到視圖。

您正在發送帶有數據的重定向,該重定向會將所述數據閃爍到會話中,以便您可以從會話中檢索它並將其發送到視圖,如下所示。

return View::make('frontend.post.play', ['code' => session('code')]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM