0
我是laravel的新手,我對某些代碼有點困惑。 我正在驗證註冊表單。 問題是,提交表單後,輸入消失了(是的,我正在使用 - >輸入)。 我從routes.php重定向到控制器,然後我重新回到視圖,但輸入消失了。Laravel輸入雙重定向
UserController中:
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'=>'[email protected]', 'as' => 'sessions.store']); //login
Route::get('logout', '[email protected]');
Route::get('register', '[email protected]');
查看
{{ 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 protected]', '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() }}
你的視圖文件是什麼樣子? – Marwelln 2014-10-27 07:37:57
安裝調試欄並在提交時檢查會話變量。 – itachi 2014-10-27 09:57:42
視圖添加並清理了其他文件 – jasper 2014-10-27 10:49:09