【问题标题】:Laravel withinput double redirectLaravel withinput 双重重定向
【发布时间】:2014-12-22 05:29:01
【问题描述】:

我是 laravel 的新手,对一些代码有些困惑。 我正在验证注册表单。 问题是提交表单后输入消失了(是的,我正在使用->withinput)。 我从 routes.php 重定向到控制器,然后我重定向回视图,但输入消失了。

用户控制器:

public function store()
{
    $input = Input::all();

    if( ! $this->user->fill($input)->isValid())
    {
        return Redirect::back()->withInput()->withErrors($this->user->messages)->with('action', 'register');
    }
    //$this->user->save();

}

routes.php

Route::filter('checkLogin', function()
{


if(Input::GET('email') != ""){ //register

    return Redirect::to('register')->withInput();

}
});


Route::post('/login', ['before'=>'checkLogin', 'uses'=>'SessionsController@store', 'as' =>      'sessions.store']); //login
Route::get('logout', 'SessionsController@destroy');
Route::get('register', 'UsersController@store');

查看

                    {{ Form::open(['url'=>'login', 'files'=>true, 'class' => 'compact form', 'id' => 'register']) }}
                    {{ Form::checkbox('register', 'register', false, ['id' => 'openRegister']) }}
                    <div class="heading">
                        <h2 class="login">Login</h2>
                        <h2 class="register">{{ HTML::decode(Form::label('openRegister', '<i class="fa fa-chevron-left"></i>')) }} Sign Up</h2>
                    </div>
                    @if ($loginError = Session::pull('loginError'))
                    <div class="errors">
                        <p class="error">{{ $loginError }}</p>
                    </div>
                    @endif
                    <div class="fields">
                        <div class="field">
                            <i class="fa fa-user"></i>
                            {{ Form::text('username', null, ['placeholder' => 'Username', 'tabindex' => 1]) }}
                            {{ $errors->first('username') }}

                        </div>
                        <div class="field">
                            <i class="fa fa-lock"></i>
                            {{ Form::password('password', ['placeholder' => 'Password', 'tabindex' => 2]) }}
                            <a href="forgot" class="fa fa-question-circle login" title="Forgot Password?"></a>
                            {{ $errors->first('password') }}
                        </div>
                    </div>

                    <section class="login">
                        <div class="switches">
                            <div class="switch text-right">
                                {{ Form::checkbox('rememberme', 'rememberme', true, ['id' => 'rememberme', 'tabindex' => 3]) }}
                                {{ Form::label('rememberme', 'Remember Me') }}
                            </div>
                        </div>
                        <div class="buttons">
                            <div class="button">
                                {{ Form::submit('Login', ['tabindex' => 4]) }}
                            </div>
                        </div>
                        <div class="text login">
                            <p>Don't have an account yet? {{ Form::label('openRegister', 'Sign up!', ['class' => 'link']) }}</p>
                        </div>
                    </section>

                    <section class="register">
                        <div class="fields">
                            <div class="group">
                                <div class="field">
                                    {{ Form::text('fname', null, ['placeholder' => 'First Name', 'tabindex' => 5]) }}
                                    {{ $errors->first('fname') }}
                                </div>
                                <div class="field">
                                    {{ Form::text('lname', null, ['placeholder' => 'Last Name', 'tabindex' => 6]) }}
                                    {{ $errors->first('lname') }}
                                </div>
                            </div>
                            <div class="field">
                                {{ Form::email('email', null, ['placeholder' => 'email@example.com', 'tabindex' => 7]) }}
                                {{ $errors->first('email') }}
                            </div>
                            <div class="field">
                                {{ Form::text('adress', null, ['placeholder' => 'Adress Line 1', 'tabindex' => 8]) }}

                            </div>
                            <div class="field">
                                {{ Form::text('adress2', null, ['placeholder' => 'Adress Line 2', 'tabindex' => 9]) }}
                                {{ $errors->first('adress') }}
                            </div>
                            <div class="field">
                                {{ Form::text('city', null, ['placeholder' => 'City', 'tabindex' => 10]) }}
                                {{ $errors->first('city') }}
                            </div>
                            <div class="group group-l-s">
                                <div class="field">
                                    {{ Form::text('state', null, ['placeholder' => 'State / Province / Region', 'tabindex' => 11]) }}
                                    {{ $errors->first('state') }}
                                </div>
                                <div class="field">
                                    {{ Form::text('zip', null, ['placeholder' => 'Postal Code', 'tabindex' => 12]) }}
                                    {{ $errors->first('zip') }}
                                </div>
                            </div>
                            <div class="select">
                                {{ Form::select('country', $countries, $country, ['tabindex' => 13]) }}
                                {{ $errors->first('country') }}
                            </div>
                            <div class="field">
                                {{ Form::text('phone', null, ['placeholder' => 'Phone Number', 'tabindex' => 14]) }}
                                {{ $errors->first('phone') }}
                                <small>(optional)</small>
                            </div>
                        </div>
                        <div class="buttons">
                            <div class="button">
                                {{ Form::submit('Sign Up', ['tabindex' => 15]) }}
                            </div>
                        </div>
                    </section>
                {{ Form::close() }}

【问题讨论】:

  • 你的视图文件是什么样的?
  • 安装调试栏并在提交时检查会话变量。
  • 查看添加并清理了其他文件

标签: validation redirect laravel input


【解决方案1】:

我没有得到输入的原因是因为我使用了 get 而不是 post。但是通过将其更改为发布我会得到其他错误。所以我只是删除了 Route::FIlter 并在 js 中定义了动作。现在我的 routes.php 看起来像这样:

Route::get('/', 'HomeController@showWelcome');

Route::get('/profile/{username}', 'UsersController@show');


Route::post('/login', ['uses'=>'SessionsController@store', 'as' => 'sessions.store']); //login
Route::post('/register', ['uses'=>'UsersController@store', 'as' => 'users.store']); //register

Route::get('logout', 'SessionsController@destroy');
Route::get('credits',function(){
return View::make('credits')->with('credits', 'credits');
});

【讨论】:

    猜你喜欢
    • 2014-01-16
    • 1970-01-01
    • 2023-01-22
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    • 2015-08-24
    相关资源
    最近更新 更多