2016-08-25 42 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() }}