samedi 28 février 2015

Keep form values when redirect back in Laravel 4

I'm trying to keep the values of a form when Redirect::back on Laravel 4, but I can't find a way to do this.


This is my form:



{{ Form::open(array('route' => 'generate', 'files' => true)) }}

{{ Form::radio('myType', '1', true); }}
{{ Form::label('myType', '1'); }}

{{ Form::radio('myType', '2'); }}
{{ Form::label('myType', '2'); }}

{{ Form::radio('myType', '3'); }}
{{ Form::label('myType', '3'); }}

{{ Form::text('myName'); }}

{{ Form::file('uploadImage'); }}

{{ Form::submit('Go'); }}

{{ Form::close() }}


And my controller:



$validator = Validator::make(Input::all(), array('uploadImage' => 'required|image', 'myName' => 'required'));

if ($validator->fails()){
return Redirect::back()->withErrors($validator);
}


I tryed something like:



return Redirect::back()->withErrors($validator)->with('nameValue', Input::get('myName'));


And then in the view:



{{ Form::text('myName', $nameValue); }}


But it still doesn't work. Any help will be appreciated.


Aucun commentaire:

Enregistrer un commentaire