简体   繁体   中英

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

//page form

<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

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

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

what i wanna do is to get the textarea value from the form page, and transfer the "Input::get('playCode')" data to the 'post/createPlay' page through the'with' method so that in the 'post/createPlay' page, we can have the data tranferred in textarea(whose id is textArea) and shows in the iframe element using js by obtaining the data again from the textarea in the same page. but i tried many times ,it didn't succeed. the variable $code is just empty.

You're not passing anything to the view. You need to send $code to the view either with the 2nd parameter of View::make() or using the View's with method.

You're sending a redirect with data which flashes said data to the session so you can retrieve it from the session and send it to the view as follows.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM