2016-08-25 57 views
0

,所以我完全完成的;(我不明白如何與實心輸入回Laravel重定向重定向回用輸入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

回答

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> 
+0

THX;)我看到這個視頻教程,但有些人的評論說,它更容易使用1線「withInput()」不是每個輸入增加價值。多謝! –

0

你必須把在價值使用old('input_name')

<input class="form-control" type="text" name="in_email" id="email"> value="{{ old('in_email') }}" 
0

你仍然必須填寫您的表單字段:

示例:

<input type="text" name="username" value="{{ old('username') }}"> 
+0

Thx mate!我在視頻教程中看到了這一點,但有些評論人士告訴我們,使用1行「withInput()」比爲每個輸入添加值更容易。多謝! –

0

您可以在視圖文件中使用刀片,以避免在每個字段中使用舊的('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() }}