withInput() 不 return 数据

withInput() does not return data

我有一个 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

例如,您需要检索所有输入值中的旧数据。

<input type="text" name="firstname" value="{{ Input::old(firstname) }}">

在 Laravel doc 上阅读有关检索旧数据的更多信息。