试图验证表单Laravel4

时间:2014-05-23 20:43:36

标签: php laravel-4

您好,我试图验证我的表单。我有使用laravel4创建的表单,当我单击提交按钮时,即使我输入所有输入,它也会将我重定向到/ newsletter。这个虫子在哪里,你能帮帮我吗?

路线:

Route::get('/newsletter', 'HomeController@signNewsletter');
Route::post('/sign', 'HomeController@sign');

控制器:

public function signNewsletter() {
    $this->layout->content = View::make('home.newsletter');
}

public function sign(){
    $rules = array(
        'email'    => 'required',
        'username' => 'required',           
        'surname' => 'required'
    );

    $validation = Validator::make(Input::all(), $rules);

    if ($validation->fails())
    {
        // Validation has failed.
        return Redirect::to('/newsletter')->withErrors($validation);
    }else{
        return Redirect::to('/');
    }
}

查看:

{{ Form::open(array('url' => '/sign', 'method' =>'POST')) }}
  {{Form::token()}}
  {{Form::text('mail', null ,array( 
    'placeholder' => 'Twoj email'
  ))}}<br>
  {{Form::text('username', null ,array( 
    'placeholder' => 'Twoje imie'
  ))}}<br>
  {{Form::text('surname', null ,array(  
    'placeholder' => 'Twoje nazwisko'
  ))}}
  {{Form::submit('Click Me!')}}
{{ Form::close() }}

调试:

dd(Input::all());

// array(4) {
//  ["_token"]=> string(40) "77o2SwxRe7hhTWT6hV1MeIOi21GcuUbG1nsSD7B0"
//  ["mail"]=> string(6) "asdasd"
//  ["username"]=> string(8) "asdasdas"
//  ["surname"]=> string(6) "asdasd"
// }

1 个答案:

答案 0 :(得分:2)

您正在使用“电子邮件”作为规则,但“邮件”作为字段名称