所以我完成了;(我无法理解如何使用填充的输入重新定向Laravel
我的简单代码是:
public function postSignIn(Request $request)
{
return redirect()->back()->withInput();
}
我的视图刀片是:
<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>
但每次所有输入都是空的
我做错了什么?
THX
答案 0 :(得分:1)
您需要对需要输入的所有元素使用old
,请参阅下面的示例:
<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>
答案 1 :(得分:0)
您必须使用old('input_name')
<input class="form-control" type="text" name="in_email" id="email"> value="{{ old('in_email') }}"
答案 2 :(得分:0)
您仍然必须填写表单字段:
示例:
<input type="text" name="username" value="{{ old('username') }}">
答案 3 :(得分:0)
您可以在视图文件中使用blade,以避免在每个字段中使用旧的('input_field_name')。在Blade模板中编写html代码,如果发生任何验证错误,它会自动处理CSRF令牌和旧输入。只需将您的HTML代码重写为: -
{{ 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() }}