Here is my typical form
$errors = array();
if ($this->request->post('submit')) { // <----- I don't like this line
$post = Validation::factory($this->request->post())
->rule('email', 'not_empty')
->rule('email', 'email')
->rule('password', 'not_empty');
if ($post->check()) {
// ok, do something
}
$errors = $post->errors(true);
}
$this->template->content = View::factory('auth/register')
->set('errors', $errors);
As you see - I check if there is a submit element which means that we have actually posted form, not just requested for the first show.
If we remove that condition - we will have validation errors for the first page request. The errors about empty email and password form. Which is actually just incorrect.
So how do you solve this issue?