i am new to kohana.
any body here to help me out??
:(

Recommended Answers

All 11 Replies

You forgot to specify with what ? Something you cannot find in the documentation ?

You forgot to specify with what ? Something you cannot find in the documentation ?

i am totally ne wto kohana. i ve read documentation but could not able to generate error messages on form validation. although validation is working but not able to generate errors :(

Can you post your code? And you might get more help in the Kohana forum.

Can you post your code? And you might get more help in the Kohana forum.

the code in which validation is being done

private function validate()
        {
                $validate   =   new Validation($_POST);
                $validate->add_rules('firstName','required');
                $validate->add_rules('lastName','required');
                $validate->add_rules('userName','required');
                $validate->add_rules('password','required');
                $validate->add_rules('address','required');
                $validate->add_rules('email', 'required', 'email');
                if(Captcha::valid($_POST['captcha_response'])){
                
                $valid   =  $validate->validate();
                if($valid){
                return $valid;
                }
                }
        }

the code where i want to generate error messages

public function createUser() {
        $validate   =   $this->validate();
        if ($validate) {
            $userData = array(
                'first_name'    => $_POST['firstName'],
                'last_name'     => $_POST['lastName'],
                'user_email'    => $_POST['email'],
                'user_password' => $_POST['password'],
                'user_address'  => $_POST['address'],
                'user_name'     => $_POST['userName']
            );

            $this->mUser->create($userData);
            $this->vTemplate->set('pageTitle', 'easyAd-admin | Thankyou');

            $this->vContent = new View('message');
            $this->vContent->set('process', 'signUp');
            $this->vTemplate->set('content', $this->vContent->render(FALSE));
            $this->vTemplate->render(TRUE);
        } else {
            $this->captcha = new Captcha;
                
            $this->vTemplate->set('pageTitle', 'easyAd-admin | Signup');
            $this->vContent = new View('sign_up');
            $this->vContent->set('captcha', $this->captcha);
            $this->vContent->set('errors',$validate->error('form_error_messages'));
            $this->vTemplate->set('content', $this->vContent->render(FALSE));
            $this->vTemplate->render(TRUE);
           
                      
        }
    }

but in else condition i m getting error
"
Fatal error: Call to a member function error() on a non-object in C:\xampp\htdocs\admin\application\controllers\user.php on line 90"

i have read kohana documentation and put my query on discussion forum too but still no response

Member Avatar for diafol

have you created an object? Perhaps it would help if you posted the relevant code (e.g. line 90 of user.php).

have you created an object? Perhaps it would help if you posted the relevant code (e.g. line 90 of user.php).

yes
line 90 is line 26 in posted code and i ve created an object in validate() function

Show your validate function. Problem is most likely there.

this is my validate function

private function validate()
    {
    $validate = new Validation($_POST);
    $validate->add_rules('firstName','required');
    $validate->add_rules('lastName','required');
    $validate->add_rules('userName','required');
    $validate->add_rules('password','required');
    $validate->add_rules('address','required');
    $validate->add_rules('email', 'required', 'email');
    if(Captcha::valid($_POST['captcha_response'])){
     
    $valid = $validate->validate();
    if($valid){
    return $valid;
    }
    }
    }

It returns only true when it validates, it does not return your $validate object on failure.

public function createUser() {
                $validate   =   new Validation($_POST);
                $validate->add_rules('firstName','required');
                $validate->add_rules('lastName','required');
                $validate->add_rules('userName','required');
                $validate->add_rules('password','required');
                $validate->add_rules('address','required');
                $validate->add_rules('email', 'required', 'email');
                if(Captcha::valid($_POST['captcha_response']))
                {
                    $valid  =   $validate->validate();
                    
                                       
                    if ($valid) {
                        var_dump($valid);
                        $userData = array(
                        'first_name'    => $_POST['firstName'],
                        'last_name'     => $_POST['lastName'],
                        'user_email'    => $_POST['email'],
                        'user_password' => $_POST['password'],
                        'user_address'  => $_POST['address'],
                        'user_name'     => $_POST['userName']
                    );
                    $this->mUser->create($userData);
                    $this->vTemplate->set('pageTitle', 'easyAd-admin | Thankyou');

                    $this->vContent = new View('message');
                    $this->vContent->set('process', 'signUp');
                    $this->vTemplate->set('content', $this->vContent->render(FALSE));
                    $this->vTemplate->render(TRUE);
                    }
                    
                   }
                    else{
                    $this->captcha = new Captcha;
               
                    $this->vTemplate->set('pageTitle', 'easyAd-admin | Signup');
                    $this->vContent = new View('sign_up');
                    $this->vContent->set('captcha', $this->captcha);
                    $this->vContent->set('errors',$validate->errors('form_error_messages'));
                    $this->vTemplate->set('content', $this->vContent->render(FALSE));
                    $this->vTemplate->render(TRUE);
                    
                    
                    }

here i have removed the above error about calling function of a non object but still not getting error messages in the form

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.