简体   繁体   English

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

[英]Register and Login form in one page in laravel 5.3

I was creating a page which have both register and login in one page. 我正在创建一个在一个页面中同时注册和登录的页面。
My code looks like this 我的代码看起来像这样

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

I use bootstrap and w3schools for styling. 我使用bootstrap和w3schools进行造型。

The problem which i get is that when i submit any one form with empty inputs it give me error in both the forms. 我得到的问题是,当我提交任何一个带有空输入的表单时,它会给我两个表单中的错误。
That is (for example), when i submit the login form with empty email and password fields, the error shows in login form and register form, that the field is empty. 那是(例如),当我提交带有空电子邮件和密码字段的登录表单时,错误显示在登录表单和注册表单中,该字段为空。
How can i fix it? 我该如何解决? I want to show errors differently. 我想以不同的方式显示错误。
Still have any doubt about my code or my question please comment below. 仍然对我的代码或我的问题有任何疑问,请在下面评论。
I even looked this for help but it was laravel 5.2, laravel 5.3 have different auth route system 我甚至看了这个寻求帮助,但它是laravel 5.2,laravel 5.3有不同的auth路由系统

Thats because you are showing the errors on both of them {{ $errors->has('email') ? 'has-error has-feedback' : '' }} 那是因为你在两个{{ $errors->has('email') ? 'has-error has-feedback' : '' }}上显示错误{{ $errors->has('email') ? 'has-error has-feedback' : '' }} {{ $errors->has('email') ? 'has-error has-feedback' : '' }} That string of code is in both the register and the login form so therefore the errors will show on them both. {{ $errors->has('email') ? 'has-error has-feedback' : '' }}该字符串代码同时包含在寄存器和登录表单中,因此错误将显示在它们两者上。

One solution could be to create the validation yourself using PHP & jQuery/JavaScript, This way you can fully customise the errors etc. It would take a bit longer and is slightly harder to do but its doable 一个解决方案可能是使用PHP和jQuery / JavaScript自己创建验证,这样你就可以完全自定义错误等。这需要更长的时间并且稍微难以做但是它可行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM