我有Laravel表格。它有一个验证表格。验证时,如果存在验证错误,则假设返回错误。它告诉完善错误,但字段丢失了用户编写的所有数据。一切都是空的。 withInput()
函数不应该做这个工作吗?
如果你需要更多的东西告诉我,我会在这里写我的控制器。
$validate = Validator::make(Input::all(), array(
'firstname' => 'required',
'lastname' => 'required',
'email1' => 'required|email',
'email2' => 'required|same:email1',
'password1' => 'required|min:6',
'password2' => 'required|same:password1',
'g-recaptcha-response' => 'required|recaptcha',
));
$captcha=Input::get('g-recaptcha-response');
//CAPTCHA CODE
if ($validate->fails())
{
return Redirect::route('getApplication')->withErrors($validate)->withInput();
}
我的观点在这里,因为你要求它:
@extends('templates.default.master')
@section('head')
@parent
<title>Application</title>
<script src='https://www.google.com/recaptcha/api.js'></script>
@stop
@section('content')
<form role="form" method="post" action="{{ URL::route('postApplication') }}">
<div class="form-group col-xs-6 {{ ($errors->has('firstname')) ? ' has-error' : '' }}">
<label for="firstname">First Name</label>
<input id="firstname" name="firstname" type="text" class="form-control">
@if($errors->has('firstname'))
{{ $errors->first('firstname') }}
@endif
</div>
<div class="form-group col-xs-6 {{ ($errors->has('lastname')) ? ' has-error' : '' }}">
<label for="lastname">Last Name</label>
<input id="lastname" name="lastname" type="text" class="form-control">
@if($errors->has('lastname'))
{{ $errors->first('lastname') }}
@endif
</div>
<div class="form-group col-xs-6 {{ ($errors->has('email1')) ? ' has-error' : '' }}">
<label for="email1">Email</label>
<input id="email1" name="email1" type="text" class="form-control">
@if($errors->has('email1'))
{{ $errors->first('email1') }}
@endif
</div>
<div class="form-group col-xs-6 {{ ($errors->has('email2')) ? ' has-error' : '' }}">
<label for="email2">Confirm Email</label>
<input id="email2" name="email2" type="text" class="form-control">
@if($errors->has('email2'))
{{ $errors->first('email2') }}
@endif
</div>
<div class="form-group col-xs-6 {{ ($errors->has('password1')) ? ' has-error' : '' }}">
<label for="passsword1">Password</label>
<input id="password1" name="password1" type="password" class="form-control">
@if($errors->has('password1'))
{{ $errors->first('password1') }}
@endif
</div>
<div class="form-group col-xs-6 {{ ($errors->has('password2')) ? ' has-error' : '' }}">
<label for="passsword2">Confirm Password</label>
<input id="password2" name="password2" type="password" class="form-control">
@if($errors->has('password2'))
{{ $errors->first('password2') }}
@endif
</div>
<div class="g-recaptcha col-xs-12" data-sitekey="6LeQAgATAAAAAAfJ-blWgKvb5-rUyp9xuo-iCdF9"></div>
<div class="form-group col-xs-12">
@if($errors->has('g-recaptcha-response'))
{{ $errors->first('g-recaptcha-response') }}
@endif
</div>
{{ Form::token() }}
<div class="form-group col-xs-12">
<input type="submit" value="Submit Application" class="btn btn-success">
</div>
</form>
@stop
答案 0 :(得分:1)
您需要在所有输入值中检索旧数据,例如。
<input type="text" name="firstname" value="{{ Input::old(firstname) }}">
阅读有关在Laravel doc上检索旧数据的更多信息。