我是 Laravel4 世界的新手,我正在尝试将我的网站转换为 laravel 框架。但一开始我有一个小问题。在索引上,我有两个 jquery 模式:第一个用于唱歌,第二个用于注册。所以,我想当用户尝试登录并出错时向他显示错误。注册也一样。但是当我在唱歌表格中出现错误时,我会收到注册表......我的英语不好,所以这里是代码:
路由.php
Route::get('/', function()
{
return View::make("index.index");
}
Route::post('/', array('as'=> 'singin', function()
{
$data = Input::all();
$rules = array(
'username' => 'min:3',
'password' => 'min:6'
);
$validation = Validator::make($data, $rules);
if($validation->passes())
{
return View::make('users.main');
}
Input::flash();
return Redirect::to('/')->withErrors($validation);
}));
Route::post('/', array('as'=> 'register', function()
{
// same as previous function
]
index.blade.php
<div id="signin" class="reveal-modal" @if($errors->all())
style="display:block; visibility:visible;" @endif >
<header class="reveal-modal-header">
Sign in
</header>
<div class="cont">
<div class="indication">
Sign In
</div>
{{ Form::open(array(
'route' => 'singin',
'class' => 'signin')) }}
<p class="clearfix">
{{ Form::label('username', 'Username') }}
{{ Form::text('username')}}
</p>
<p class="clearfix">
{{ Form::label('password', 'Password') }}
{{ Form::password('password')}}
</p>
<p class="without-label clearfix">
{{ Form::submit('') }}
</p>
@if($errors->all())
<div id="logindiverror" style="" class="alert alert-error">
@foreach($errors->all('<li>:message</li>') as $message)
{{ $message }}
@endforeach
</div>
@endif
{{ Form::close() }}
</div>
<a class="close-reveal-modal" id="close1" href="#">×</a>
</div>
<div id="signup" class="reveal-modal" @if($errors->all())
style="display:block; visibility:visible;" @endif >>
<header class="reveal-modal-header">
Sign up
</header>
<div class="cont">
<div class="indication">
Register
</div>
{{ Form::open(array(
'route' => 'register',
'class' => 'signup')) }}
<p class="clearfix">
<em>(<abbr>*</abbr>) All fields are required</em>
</p>
<p class="clearfix">
<label>Username:<abbr>*</abbr></label>
{{ Form::text('username')}}
</p>
<p class="clearfix">
<label>Email:<abbr>*</abbr></label>
{{ Form::text('email') }}
</p>
<p class="clearfix">
<label>Password:<abbr>*</abbr></label>
{{ Form::password('password1'); }}
</p>
<p class="clearfix">
<label>Password (repeat):<abbr>*</abbr></label>
{{ Form::password('password2'); }}
</p>
<p class="checkboxes clearfix">
<span class="niceCheck">{{ Form::checkbox('agree', '0') }}</span>
I agree with LinkyPlanet Terms & Privacy Policy
</p>
<p class="without-label clearfix">
{{ Form::submit('') }}
</p>
@if($errors->all())
<div id="logindiverror" style="" class="alert alert-error">
@foreach($errors->all('<li>:message</li>') as $message)
{{ $message }}
@endforeach
</div>
@endif
{{ Form::close() }}
</div>
<a class="close-reveal-modal" id="close2" href="#">×</a>
</div>
所以,问题是当用户尝试唱歌时,他输入了密码错误(密码短于 6 个字符),脚本将他重定向到索引并打开模式进行注册,并且显示错误,而不是在模式中唱歌。错在哪里?
干杯:)