How can I redirect with old input in Laravel?

Asked
Active3 hr before
Viewed126 times

8 Answers

redirectinput
90%

Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers , Meta Stack Overflow , Stack Overflow Public questions & answers ,Connect and share knowledge within a single location that is structured and easy to search.

You are missing the value on your input element...

value = "{{ Input::get ('username', '') }}"
load more v
88%

return Redirect::back()->withErrors(['msg', 'The Message']);

and inside your view call this

@if($errors->any())
<h4>{{$errors->first()}}</h4>
@endif
load more v
72%

When working on forms with "array" inputs, you may use dot notation to access the arrays:,You may access all user input with a few simple methods. You do not need to worry about the HTTP verb used for the request, as input is accessed in the same way for all verbs.,Note: You may flash other data across requests using the Session class., Getting Started Installation Configuration Homestead Request Lifecycle Routing Requests & Input Views & Responses Controllers Errors & Logging

Retrieving An Input Value

$name = Input::get('name');
load more v
65%

I have a login modal. When the user log-in fail the authentication, I want to redirect back to this modal with :,As you can see as part of my image, the error message seem to display, but the old input of username doesn't seem to populate.,Can someone please correct me ? Did I forget to do anything ? What is the most efficient way in Laravel to accomplish something like this ?,Well, for the CRUD stuff, I'd simply redirect to the routes of the previous action, usually something like admin-index, administrate or whatever. I don't really see why you would need the HTTP_REFERER in that case. If however you still want to access the HTTP_REFERER it's as simple as this:

Controller

// if Auth Fail 
return Redirect::to('/') -
   > with('error', 'Username/Password Wrong') -
   > withInput(Request::except('password')) -
   > withErrors($validator);

Form

{!! Form::open(array('url' => '/', 'class' => 'login-form')) !!}

  <div class="form-group">
    <label for="username">Username</label>
    <input type="text" class="form-control"  id="username" name="username" placeholder="Enter Username" required>
  </div>
  <div class="form-group">
    <label for="password">Password</label>
    <input type="password" class="form-control" id="password" name="password" placeholder="Enter Password" required>
  </div>
  <button type="submit" class="btn btn-primary">Login</button>

{!! Form::close() !!}
load more v
75%

I have a login modal. When the user log-in fail the authentication, I want to redirect back to this modal with :,As you can see as part of my image, the error message seem to display, but the old input of username doesn't seem to populate.,Currently this is my view And this is the output I wanted to display something like this It's pretty easy. First of all send to the view decoded variable (see L...,Can someone please correct me ? Did I forget to do anything ? What is the most efficient way in Laravel to accomplish something like this ?

Controller

// if Auth Fail 
return Redirect::to('/') -
   > with('error', 'Username/Password Wrong') -
   > withInput(Request::except('password')) -
   > withErrors($validator);
load more v
40%

I have a login modal. When the user log-in fail the authentication, I want to redirect back to this modal with :,and redirect to the view with:,Can someone please correct me ? Did I forget to do anything ? What is the most efficient way in Laravel to accomplish something like this ?,As described in the docs it is more convenient in a blade view.

Controller

// if Auth Fail 
return Redirect::to('/') -
   > with('error', 'Username/Password Wrong') -
   > withInput(Request::except('password')) -
   > withErrors($validator);

Form

{!! Form::open(array('url' => '/', 'class' => 'login-form')) !!}

  <div class="form-group">
    <label for="username">Username</label>
    <input type="text" class="form-control"  id="username" name="username" placeholder="Enter Username" required>
  </div>
  <div class="form-group">
    <label for="password">Password</label>
    <input type="password" class="form-control" id="password" name="password" placeholder="Enter Password" required>
  </div>
  <button type="submit" class="btn btn-primary">Login</button>

{!! Form::close() !!}
load more v
22%

Route::get('/redirecttest2', function () { return Redirect::back()->withInput(Input::except('foo')); });,"return Redirect::back()->withInput([]);" causes the redirect to include all of the previous input, instead of none of it.,This can be shown really quick in route closures as follows: Navigating to this /redirecttest route should cause an infinite redirect loop, since the first route redirects to the second, and the second should redirect back to the first WITHOUT old('foo') being set. Instead it will display "whoops". Route::get('/redirecttest', function () { if (old('foo')) { dd('whoops'); } return Redirect::to('redirecttest2?foo=bad'); });,However, this second example works as expect (by outputting "yay"): Route::get('/redirecttest', function () { if (old('foo')) { dd('whoops'); } if (old('bar')) { dd('yay'); } return Redirect::to('redirecttest2?foo=bad&bar=good'); });

Since 5.2 i not supported anymore we can't fix it there, so use null instead of an empty array. Will look into fixing it in 5.4 though.

null
60%

You can redirect with old data like below with validation error,Read more: http://laravel.com/docs/5.0/requests#old-input

$username = Request::old('username');
load more v

Other "redirect-input" queries related to "How can I redirect with old input in Laravel?"