简体   繁体   English

在同一页面上登录和注册表单Laravel 5.6

[英]Login and Register form on the same page Laravel 5.6

My login and register page is the same. 我的登录和注册页面是相同的。 So when I fill the register page with wrong credentials, errors appear for both login and register forms. 因此,当我用错误的凭据填写注册页面时,登录表单和注册表单都会出现错误。

How can I fix this issue from a Submit button onclick event and make the login page hidden? 如何通过“提交”按钮onclick事件解决此问题并使登录页面隐藏? Alternative suggestions accepted. 接受其他建议。

Note: I am using laravel and jquery. 注意:我正在使用laravel和jquery。 But I don't want to change it from server side. 但是我不想从服务器端更改它。

Edit: When the registration fail it should be focus on register page but it is focusing the login page. 编辑:当注册失败时,应该将焦点放在注册页面上,但是将焦点放在登录页面上。

What is the easiest way to make it work? 使它工作最简单的方法是什么? Any suggestions? 有什么建议么? I don't know how to use error bags It would be fine if someone also tell me how to do it. 我不知道如何使用错误袋如果有人也告诉我该怎么做会很好。 Many thanks. 非常感谢。

I tried this but the button should be submit button so it doesn't work: 我尝试了此操作,但该按钮应为“提交”按钮,因此它不起作用:

    document.getElementById("login_id").style.visibility = "hidden";

Here the html code; 这是html代码;

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <title>MaterialLab - jQuery full version</title>
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,700|Poppins:300,400,500,600" rel="stylesheet">
    <link rel="icon" href="assets/img/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" href="assets/css/vendor.bundle.css">
    <link rel="stylesheet" href="assets/css/app.bundle.css">
    <link rel="stylesheet" href="assets/css/theme-a.css">
</head>
<body id="auth_wrapper">
<div id="login_wrapper">

    <div id="login_content">
        <div class="logo">
            <img src="assets/img/logo/ml-logo.png" alt="logo" class="logo-img">
        </div>
        <h1 class="login-title">
            Sign In to your account
        </h1>
        <div class="login-body">
            <form id="1" style="visibility: visible" method="POST" action="{{ route('login') }}">
                @csrf
                <div class="form-group label-floating is-empty">
                    <label class="control-label">Email</label>
                    <input type="email" name="email" class="form-control"  value="{{ old('email') }}" required>

                    @if ($errors->has('email'))
                        <span class="invalid-feedback">
                            <strong>{{ $errors->first('email') }}</strong>
                         </span>
                    @endif

                </div>
                <div class="form-group label-floating is-empty">
                    <label class="control-label">Password</label>
                    <input type="password" name="password" class="form-control" required>

                    @if ($errors->has('password'))
                        <span class="invalid-feedback">
                            <strong>{{ $errors->first('password') }}</strong>
                        </span>
                    @endif

                </div>
                <a href="javascript:void(0)" class="forgot-pass pull-right">Forgot Password?</a>
                <div class="checkbox inline-block">
                    <label>
                        <input type="checkbox" class="checkbox-inline" value="">
                        Remember Me
                    </label>
                </div>
                <button type="submit" class="btn btn-info btn-block m-t-40">Sign In</button>
                <div class="login-options">
                    <span>OR</span>
                    <hr/>
                </div>
                <div class="row">

                    <div class="col-xs-12">
                        <button class="btn btn-google btn-block"><i class="zmdi zmdi-google-plus"></i> Sign In with
                            Google
                        </button>
                    </div>

                </div>
            </form>
        </div>
        <div class="login-footer p-15">
            <p>
                Don't have an account? <a href="javascript:void(0)" data-toggle="register">Create an account</a>
            </p>
        </div>
        <div id="register_wrapper">
            <ul class="card-actions icons right-top">
                <li>
                    <a href="javascript:void(0)" data-toggle="register">
                        <i class="zmdi zmdi-close"></i>
                    </a>
                </li>
            </ul>
            <div class="logo">
                <img src="assets/img/logo/ml-logo.png" alt="logo" class="logo-img">
            </div>
            <h1 class="login-title">
                Create an account
            </h1>


                <div class="col-xs-12">
                    <button class="btn btn-google btn-block"><i class="zmdi zmdi-google-plus"></i> Sign Up with Google
                    </button>
                </div>


                <form class="clear-both"  method="POST" action="{{ route('register') }}">
                    @csrf
                    <h2 class="text-center p-t-20">
                        Or sign up below
                    </h2>
                    <div class="form-group label-floating is-empty">
                        <label class="control-label">Name</label>
                        <input type="text" name="name" class="form-control" required>
                        @if ($errors->has('name'))
                            <span class="invalid-feedback">
                                        <strong>{{ $errors->first('name') }}</strong>
                                    </span>
                        @endif
                    </div>

                    <div class="form-group label-floating is-empty">
                        <label class="control-label">Email</label>
                        <input type="email" name="email" class="form-control" required>

                        @if ($errors->has('email'))
                            <span class="invalid-feedback">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                        @endif
                    </div>

                    <div class="form-group label-floating is-empty">
                        <label class="control-label">Password</label>
                        <input type="password" name="password" class="form-control" required>

                        @if ($errors->has('password'))
                            <span class="invalid-feedback">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                        @endif
                    </div>

                    <div class="form-group label-floating is-empty">
                        <label class="control-label">Confirm Password</label>
                        <input type="password" name="password_confirmation" class="form-control" required>
                    </div>

                    <button type="submit" name="submit" onClick="makeLoginFormHidden()" class="btn btn-info btn-block m-t-40">Create my account</button>
                </form>
            </div>
            <div class="login-footer p-15">
                <p>
                    Already have an account? <a href="javascript:void(0)" data-toggle="register">Sign In</a>
                </p>
            </div>
        </div>
    </div>
</div>
<script>
    function makeLoginFormHidden() {
        document.getElementById("1").style.visibility = "hidden";
    }
</script>
<script src="assets/js/vendor.bundle.js"></script>
<script src="assets/js/app.bundle.js"></script>
</body>
</html>

Check what kind of error it is by simply setting and getting session variables 只需设置并获取会话变量即可检查出哪种错误

// From login action
Session::flash('login_error',true);

// In the view

@if(Session::has('login_error'))
    // activate the login form and show the error
@endif  

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

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