Laravel 5.6提交了$ errors检查表?

时间:2018-07-26 17:07:26

标签: php laravel laravel-5 laravel-5.6

我有一个页面,其中包含注册表格和登录表格。两者都传递类似的变量,例如emailpassword等。因此,我需要知道哪种形式在Laravel 5.6中产生了错误。我敢肯定这很简单,但我找不到任何答案。谢谢。

我的代码:

<!-- SIGN IN/UP FORM -->
        <div class="form-custom text-center container bg-white">
        @if(Session::has('message'))
            <div class="h1 text-success">
                {{ Session::get('message') }}
            </div>
        @endif

            <img src="images/logo.png" alt="">

            <!-- TAB CONTENT -->
            <div class="tab-content mt-5">
                <div id="signin" class="tab-pane fade show active">
                    <!--SIGN IN-->
                    <form id="signin-form" action="{{ route('login') }}" method="post" class="mb-3">
                       @csrf
                        <div class="container px-4">
                            <input class="form-style" type="text" name="email" placeholder="Email" autocomplete="off" required>
                            <input class="form-style" type="password" name="password" placeholder="Password" required>
                        </div>
                    </form>
                    <!--SIGN IN-->
                </div>

                <div id="signup" class="tab-pane fade">
                    <!--SIGN UP-->
                    <form id="signup-form" action="{{ route('register') }}" method="post" class="mb-3">
                       @csrf
                        <div class="container px-4">
                            <input class="form-style" type="text" name="first_name" placeholder="First Name" required>
                            <input class="form-style" type="text" name="last_name" placeholder="Last Name" required>
                            <input class="form-style" type="text" name="email" placeholder="Email" autocomplete="off" required>
                            <input class="form-style" type="password" name="password" placeholder="Password" required>
                            <input type="hidden" name="account_type" value="3" required>
                        </div>
                    </form>
                    <!--SIGN UP-->
                </div>

                <div id="filmmaker" class="tab-pane fade">
                    <!-- FILMMAKER -->
                    <form id="filmmaker-form" action="" method="post" class="mb-3">
                       @csrf
                        <div class="container px-4">
                            <input class="form-style" type="text" name="first_name" placeholder="First Name" required>
                            <input class="form-style" type="text" name="last_name" placeholder="Last Name" required>
                            <input class="form-style" type="email" name="email" placeholder="Email" autocomplete="off" required>
                            <input class="form-style" type="text" name="company_name" placeholder="Company Name" required>
                            <input class="form-style" type="password" name="password" placeholder="Password" required>
                            <input type="hidden" name="account_type" value="2" required>
                        </div>
                    </form>
                    <!-- FILMMAKER -->
                </div>
            </div>
            <!-- TAB CONTENT -->

              <ul class="nav nav-pills">
                 <li class="active">
                     <button data-toggle="pill" href="#signin" class="active btn btn-sign">Sign in</button>
                 </li>
                 <li>
                     <button data-toggle="pill" href="#signup" class="btn btn-sign">Sign up</button>
                 </li>
                 <li>
                    <h1 data-toggle="pill" href="#filmmaker" class="lead {{ $errors->any() ? 'filmmaker-error-text' : null }} filmmaker-custom mt-3">Are you a filmmaker?</h1>
                 </li>
             </ul>
            @if($errors->any() && old('login'))
                <div class="text-danger">Email and password combination is incorrect</div>
            @elseif($errors->any() && old('register'))
                <div class="text-danger">Please check your signup information</div>
            @endif
        </div>
        <!-- SIGN IN/UP FORM -->

1 个答案:

答案 0 :(得分:1)

最好的方法是根据登录名或注册表为输入名称加上前缀。但是我想你不想用这种方式做事,所以试试这个

    <form action="signin" method="POST">

       <input type="email" name="email" />
       @if($errors->has('email') && old('mode') == 'signin'))
           {!! errors->first('email', '<span class="help-block'>:message</span>') !!}
       @endif
       <input type="password" name="password" />
       <input type="submit" name="mode" value="signin"/>
    </form>

    <form action="signup" method="POST">
       <input type="email" name="email" />
       @if($errors->has('email') && old('mode') == 'signup))
           {!! errors->first('email', '<span class="help-block'>:message</span>') !!}
       @endif
       <input type="password" name="password" />
       <input type="submit" name="mode" value="signup"/>
    </form>