php - Laravel Post Form data -


i having trouble taking data form in laravel app, , displaying using method in same controller.

this formcontroller

class forumcontroller extends controller { + +   private $name, +           $description; + +   public function __construct() { +       $this->middleware('auth'); +   } + +   /** +    * show form creating new resource. +    * +    * @return response +    */ +   public function create() +   { +       return view('forum.create');         + +       $this->name = input::post('name');   +   } + +   /** +    * show details of input once created +    */ +   public function created() +   {    +       var_dump($this->name); +   } +} 

this routes.php

route::get('/group/create', 'forumcontroller@create'); +route::post('/group/create', 'forumcontroller@created'); 

this forum create view.

@extends('app') + +@section('content') +    +   <div class="container"> +       <h1>create forum</h1> +       <hr> +        +       <div class="panel panel-default"> +           <div class="panel-heading">create own forum here!</div> +            +           <div class="panel-body"> +               @if (count($errors) > 0) +                   <div class="alert alert-danger"> +                       <strong>whoops!</strong>there problems input.<br><br> +       <ul> +           @foreach ($errors->all() $error) +               <li>{{ $error }}</li> +           @endforeach +       </ul> +               @endif +               <form class="form-horizontal" method="post" action="{{ url('/group/create') }}"> + +                   <input type="hidden" name="_token" value="{{ csrf_token() }}">   +                    +                   <div class="form-group"> +                       <label class="col-md-4 control-label">name</label> +                       <div class="col-md-6"> +                           <input type="text" class="form-control" name="name" min="1" max="20"> +                       </div> +                   </div> + +                   <div class="form-group"> +                       <label class="col-md-4 control-label">description</label> +                       <div class="col-md-6"> +                           <input type="text" class="form-control" name="description" min="1" max="255"> +                       </div> +                   </div> +                    +                   <div class="form-group"> +                       <div class="col-md-6 col-md-offset-4"> +                           <button type="submit" class="btn btn-primary"> +                               create +                           </button> +                       </div> +                   </div> +               </form> +           </div> +       </div>   +   </div>   +@stop 

could point me in right direction please?

well, point of failure on example php not going persist $this->name when load created route. in fact, commenter stated, $this->name never set because have return statement prior definition.

after set $this->name in create method. when navigate created route, $this->name no longer set, if move return statement after setting of name.

you need pesist data in database/session/cache or redirect create method created method passing data.

public function create()  {     // handle post here     if (input::has('name')) {        $this->name = input::get('name');           // $this->name redundant still...         return redirect::to('created', array('name' => $this->name));     }      return view('forum.create');         } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -