Reputation: 55
So i am totally done ;( I can't understand how to redirect back on Laravel with filled inputs
My simple code is:
public function postSignIn(Request $request)
{
return redirect()->back()->withInput();
}
My view blade is:
<form action="{{ route('signin') }}" method="post">
<div class="form-group {{$errors->has('in_email') ? 'has-error' : ''}}">
<label for="email">Your E-Mail</label>
<input class="form-control" type="text" name="in_email" id="email">
@if ($errors->has('in_email'))
<span class="help-block">{{$errors->first('in_email')}}</span>
@endif
</div>
<div class="form-group {{$errors->has('in_password') ? 'has-error' : ''}}">
<label for="password">Your Password</label>
<input class="form-control" type="password" name="in_password" id="password">
@if ($errors->has('in_password'))
<span class="help-block">{{$errors->first('in_password')}}</span>
@endif
</div>
{{ csrf_field() }}
<button type="submit" class="btn btn-primary">Submit</button>
</form>
But every time all inputs are empty
What i am doing wrong?
thx
Upvotes: 0
Views: 5632
Reputation: 511
You can use blade in view file to avoid to use old('input_field_name') in every field. Writing your html code in Blade template, it automatically handle CSRF token and old input if any validation error occurs. Just rewrite your HTML code as :-
{{ Form::open(['route' => 'signin', 'method'=>'POST']) }}
<div class="form-group {{$errors->has('in_email') ? 'has-error' : ''}}">
<label for="email">Your E-Mail</label>
{{ Form::text('in_email', null, ['class'=>'form-control', 'id'=>'email']) }}
{{ $errors->first('in_email', '<span class="text-danger">:message</span>') }}
</div>
<div class="form-group {{$errors->has('in_password') ? 'has-error' : ''}}">
<label for="password">Your Password</label>
{{ Form::password('in_password', null, ['class' => 'form-control', 'id' => 'password']) }}
{{ $errors->first('in_password', '<span class="text-danger">:message</span>') }}
</div>
<button type="submit" class="btn btn-primary">Submit</button>
{{ Form::close() }}
Upvotes: 0
Reputation: 781
you still have to populate your form fields:
example:
<input type="text" name="username" value="{{ old('username') }}">
Upvotes: 0
Reputation: 4207
You need to use old
for all elements you need input, see example below:
<form action="{{ route('signin') }}" method="post">
<div class="form-group {{$errors->has('in_email') ? 'has-error' : ''}}">
<label for="email">Your E-Mail</label>
<input class="form-control" type="text" name="in_email" id="email" value="{{ old('in_email') }}">
@if ($errors->has('in_email'))
<span class="help-block">{{$errors->first('in_email')}}</span>
@endif
</div>
<div class="form-group {{$errors->has('in_password') ? 'has-error' : ''}}">
<label for="password">Your Password</label>
<input class="form-control" type="password" name="in_password" id="password" value="{{ old('in_password') }}">
@if ($errors->has('in_password'))
<span class="help-block">{{$errors->first('in_password')}}</span>
@endif
</div>
{{ csrf_field() }}
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Upvotes: 2
Reputation: 14027
You have to put in the value using the old('input_name')
<input class="form-control" type="text" name="in_email" id="email"> value="{{ old('in_email') }}"
Upvotes: 0