繁体   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