Reputation: 2339
i'm having problem when i want to validate my form in fuelphp framework
this is my code in controller
/*
* for getting request param for client and save to database
*/
public function action_input(){
$data = array();
//checking method from client
if(Input::method() == 'POST'){
$val = Validation::forge();
$val->add('name','Name')
->add_rule('required');
$val->add('age','Age')
->add_rule('required');
$val->add('alamat','Alamat')
->add_rule('required');
$val->add('email', 'Email address')->add_rule('match_value', '[email protected]', true)->add_rule('valid_email');
if($val->run()){
$data['name'] = Input::post('name');
$data['body'] = Input::post('age');
$data['alamat'] = Input::post('alamat');
$data['email'] = Input::post('email');
}else{
$data['error'] = $val->errors('name')->get_message('The field :label must be filled out before auth is attempted.');
}
return View::forge('testing/result', $data);
}
}
if i'm input with validate is true(all field is correct) that is not problem, but when any field is not correct i have the error like this
ErrorException [ Error ]: Call to undefined method Fuel\Core\Validation::errors()
and debugger pointing to this code
$data['error'] = $val->errors('name')->get_message('The field :label must be filled out before auth is attempted.');
i don't know what happend, but i'm still declare $val in top of statement but the error is undefined, any someone is know?.
i'm new in fuelPHP framework, maybe you can give me suggestion how to validate form in fuelphp framework like better...thanks for your answer.
Upvotes: 0
Views: 1818