2016-11-12 103 views
3

我正在創建一個頁面,它在一個頁面中同時註冊和登錄。
我的代碼看起來像這樣在laravel的一個頁面中註冊並登錄表單5.3

<div class="w3-display-container w3-white"> 
    <div style="white-space:nowrap;" class="container"> 
     <h2>Already have an account?</h2><hr> 
     <div class="col-md-8 col-md-offset-2 w3-margin-bottom"> 
      {!! Form::open(['route' => 'login', 'method' => 'POST']) !!} 
       <div class="form-group {{ $errors->has('email') ? 'has-error has-feedback' : '' }}"> 
        {{ Form::label('email', 'Enter Your Email...', ['class' => 'control-label']) }} 
        {{ Form::email('email', null, ['class' => 'form-control', 'placeholder' => 'email...', 'value' => old('email')]) }} 
        <span class="{{ $errors->has('email') ? 'glyphicon glyphicon-remove form-control-feedback' : '' }}"></span> 
       </div> 
       <div class="form-group {{ $errors->has('password') ? 'has-error has-feedback' : '' }}"> 
        {{ Form::label('password', 'Enter Your Password...', ['class' => 'control-label']) }} 
        {{ Form::password('password', ['class' => 'form-control', 'placeholder' => 'password...']) }} 
        <span class="{{ $errors->has('password') ? 'glyphicon glyphicon-remove form-control-feedback' : '' }}"></span> 
       </div> 
       {{ Form::submit('Log in', ['class' => 'btn btn-success w3-margin-top']) }} 
      {!! Form::close() !!} 
     </div> 
    </div> 
</div> 
<div class="w3-display-container w3-white"> 
    <div style="white-space:nowrap;" class="container"> 
     <h2>New Here?</h2><hr> 
     <div class="col-md-8 col-md-offset-2 w3-margin-bottom"> 
      {!! Form::open(['route' => 'register']) !!} 
       <div class="form-group {{ $errors->has('name') ? 'has-error has-feedback' : '' }}"> 
        {{ Form::label('name', 'Username...', ['class' => 'control-label']) }} 
        {{ Form::text('name', null, ['class' => 'form-control', 'placeholder' => 'username...']) }} 
        <span class="{{ $errors->has('name') ? 'glyphicon glyphicon-remove form-control-feedback' : '' }}"></span> 
       </div> 
       <div class="form-group {{ $errors->has('email') ? 'has-error has-feedback' : '' }}"> 
        {{ Form::label('email', 'Email...', ['class' => 'control-label']) }} 
        {{ Form::email('email', null, ['class' => 'form-control', 'placeholder' => 'email...']) }} 
        <span class="{{ $errors->has('email') ? 'glyphicon glyphicon-remove form-control-feedback' : '' }}"></span> 
       </div> 
       <div class="form-group {{ $errors->has('password') ? 'has-error has-feedback' : '' }}"> 
        {{ Form::label('password', 'Password...', ['class' => 'control-label']) }} 
        {{ Form::password('password', ['class' => 'form-control', 'placeholder' => 'passsword...']) }} 
        <span class="{{ $errors->has('password') ? 'glyphicon glyphicon-remove form-control-feedback' : '' }}"></span> 
       </div> 
       <div class="form-group {{ $errors->has('password') ? 'has-error has-feedback' : '' }}"> 
        {{ Form::label('password_confirmation', 'Confirm Password...', ['class' => 'control-label']) }} 
        {{ Form::password('password_confirmation', ['class' => 'form-control', 'placeholder' => 'confirm password...']) }} 
        <span class="{{ $errors->has('password') ? 'glyphicon glyphicon-remove form-control-feedback' : '' }}"></span> 
       </div> 
       {{ Form::submit('Sign Up', ['class' => 'btn btn-success w3-margin-top']) }} 
      {!! Form::close() !!} 
     </div> 
    </div> 
</div> 

我用引導和W3Schools的造型爲。

我得到的問題是,當我提交任何一個形式的空輸入它給我錯誤的兩種形式。
這是(例如),當我提交帶有空電子郵件和密碼字段的登錄表單時,錯誤顯示在登錄表單和註冊表格中,該字段爲空。
我該如何解決? 我想顯示不同的錯誤。
對我的代碼還是有疑問的,或者我的問題請在下面留言。

我甚至看了this尋求幫助,但它是laravel 5.2,laravel 5.3有不同的身份驗證路徑系統

+0

莫非你告訴具體的案件和輸入值,你在兩種形式中都會遇到錯誤。 –

回答

1

那是因爲你是顯示他們兩人的錯誤{{ $errors->has('email') ? 'has-error has-feedback' : '' }}的代碼串在寄存器和登錄都因此這些錯誤會顯示在他們兩個上。

一種解決方案可以創建自己使用PHP &的jQuery/JavaScript的驗證,這樣你就可以完全自定義的錯誤等,這將需要更長的時間,是稍硬這樣做,但它是可行的