首页 文章

在laravel 5.3中的一页中注册和登录表单

提问于
浏览
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>

我使用bootstrap和w3schools进行造型 .

我得到的问题是,当我提交任何一个带有空输入的表单时,它会给我两个表单中的错误 .
那是(例如),当我提交带有空电子邮件和密码字段的登录表单时,错误显示在登录表单和注册表单中,该字段为空 .
How can i fix it? I want to show errors differently. Still have any doubt about my code or my question please comment below.
我甚至看了this寻求帮助,但它是laravel 5.2,laravel 5.3有不同的auth路由系统

1 回答

  • 1

    那是因为你在他们两个上都显示错误 {{ $errors->has('email') ? 'has-error has-feedback' : '' }} 这个代码串同时在寄存器和登录表单中,因此错误将显示在他们两个上 .

    一个解决方案可能是使用PHP和jQuery / JavaScript自己创建验证,这样你就可以完全自定义错误等 . 这需要更长的时间并且稍微难以做但是它可行

相关问题