K
K
Kirill Gorlov2016-02-04 13:52:26
Kohana
Kirill Gorlov, 2016-02-04 13:52:26

How to handle Kohana 3.3 validation errors during user registration?

There is Kohana 3.3 installed on Apache server under Xubuntu 14.10 . The
controller is also written. application/classes/Controller/User.php
There are small wrappers of the entire application for more convenient templating; therefore, controllers are not inherited according to the standard scheme, but this never bothered me.

class Controller_User extends Controller_System_Template

There is a method
public function action_signup()
  {
    // если юзер авторизован
    if($this->_auth->logged_in())
    {
      // отправляем его на главную
      $this->redirect("/");
    }

    // если есть данные
    if ($post = $this->request->post())
    {

      try {

        $user = ORM::factory('User')->create_user($post, array('username','email','password'));
        $user->add('roles',ORM::factory('Role',array('name'=>'login')));

        mail($post['email'],
        'Регистрация на сайте SiteName',
        'Вы были зерегестрированы на сайте SiteName, ваш логин: '.$post['username'].' Ваш пароль: '.$post['password']);

        $this->redirect("/");

      }
      catch (ORM_Validtion_Exception $e)
      {
        $errors = $e->errors('validation');
        return FALSE;
      }
    }

    $this->template->content = View::factory('partials/users/signup');
  }

Actually what is the question.
How can I handle registration errors.
It gives me an error all the time when submitting the form, all fields are set correctly
ORM_Validation_Exception [ 0 ]: Failed to validate array

Swears at line 1276 :
1271 		$array = $this->_validation;
1272 
1273 		if (($this->_valid = $array->check()) === FALSE OR $extra_errors)
1274 		{
1275 			
1276 			$exception = new ORM_Validation_Exception($this->errors_filename(), $array);
1277 
1278 			if ($extra_errors)
1279 			{
1280 				// Merge any possible errors from the external object
1281 				$exception->add_object('_external', $extra_validation);

Already opened up the insides, already created a file with an array of errorsapplication/messages/validation/user.php
<?php defined('SYSPATH') OR die('No direct script access.');

return array(

  'username' => array(
    'not_empty' => 'Поле должно быть не пустым',
    'max_length' => 'Превышена длина поля',
  ),

  'password' => array(
    'not_empty' => 'Пароль задать надо',
  ),

  'email' => array(
    'not_empty' => 'Пустое поле',
    'email' => 'Ошибка почты',
  ),

);

But this did not solve the problem - the error remains the same.
I tried to write with a capital letter - on Linux, PHP still finds fault, I tried to do it according to the standard. didn't work either.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Gorlov, 2016-02-24
@Chetson

The error was in the line
Banal typo
catch (ORM_Valid a tion_Exception $e)

E
entermix, 2016-02-04
@entermix

Have you checked what's in $post after this line?

if ($post = $this->request->post())
    {

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question