我有一個始終合格的驗證程序,如果用戶名少於3個字符,我需要驗證程序。Laravel 4簡單的表單驗證
這裏是我的路線:
Route::get('/', function()
{
return View::make('validation.form');
});
Route::post('registration', function()
{
// Fetch all request data.
$data = Input::all();
var_dump($data);
// Build the validation constraint set.
$rules = array(
'username' => 'alpha_num|min:3' //or username =>array('alpha_num','min:3')
);
var_dump($rules);
// Create a new validator instance.
$validator = Validator::make($data, $rules);
if ($validator->passes()) {
// Normally we would do something with the data.
return 'Data was saved.';
}
return 'data not saved';
});
而且波紋管是「我」的形式
{{ Form::open(array('url' => 'registration')) }}
{{-- Username field. ------------------------}}
{{ Form::label('username', 'Username') }}
{{ Form::text('username') }}
<br/>
{{-- Email address field. -------------------}}
{{ Form::label('email', 'Email address') }}
{{ Form::email('email') }}
<br/>
{{-- Password field. ------------------------}}
{{ Form::label('password', 'Password') }}
{{ Form::password('password') }}
<br/>
{{-- Password confirmation field. -----------}}
{{ Form::label('password_confirmation', 'Password confirmation') }}
{{ Form::password('password_confirmation') }}
<br/>
{{-- Form submit button. --------------------}}
{{ Form::submit('Register') }}
{{ Form::close() }}
當我點擊提交按鈕,我一直排到/登記信息數據saved.Why ?不工作的驗證。任何想法
你可以添加var_dumps嗎? – clod986
數據成功通過..我也需要使用它,它失敗了空輸入..但不應該最小:3使它失敗。 – John