Welcome Guest, Not a member yet? Register   Sign In
form validation callback problem
#1

[eluser]flaky[/eluser]
Hi

I'm having kind of an issue here, the callback function for email validation is never called, I have no clue why it isn't being called, I even removed all the validation (required, valid_email) and left only the callback function, but it won't work, here is the complete code. help!!

Some info, if it helps in any way
OS: Windows 7
Web Server: IIS 7
PHP: v5.3
MySQL: v5.1.37

Code:
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');

require_once(BASEPATH . 'application/controllers/blog' . EXT);

class User extends Blog{
    
    public function User(){
        parent::Blog();
        
        //Load helpers
        $this->load->helper('form');
        
        //Load libraries
        $this->load->library('form_validation');
        
        //Load models
        $this->load->model('user_model');
    }
    
    public function index(){
        $this->load->view('user_register');
    }
    
    public function register($register=FALSE){
        if($register == TRUE){
            $this->form_validation->set_rules('user_email', 'Email', 'callback_user_email_check');
            $this->form_validation->set_rules('user_password', 'Password', 'required|min_length[6]');
        
            if ($this->form_validation->run() == TRUE){
                $data['user_email']             = $this->input->post('user_email');
                $data['user_password']             = $this->input->post('user_password');
                
                if(is_uploaded_file($_FILES['user_thumbnail']['tmp_name'])) {
                    $data['user_thumbnail']         = mysql_real_escape_string(file_get_contents($_FILES['user_thumbnail']['tmp_name']));
                    $size                             = getimagesize($_FILES['user_thumbnail']['tmp_name']);
                    $data['user_thumbnail_type']     = $size['mime'];
                }
                
                //If there are no users in the database
                //then, this user will be with administrative role and active
                //by default
                if($this->user_model->count() == 0){
                    $data['user_role_id']             = 1; //USER_ADMIN
                    $data['user_status_id']         = 1; //USER_ACTIVE
                }
                else{
                    $data['user_role_id']            = 3; //USER_LIMITED
                    $data['user_status_id']            = 2; //USER_PASSIVE
                }
                
                $this->user_model->save($data);
            }
            else
                $this->load->view('user_register');
        }
        else
            $this->load->view('user_register');
    }
    
    public function user_email_check($user_email){
        $this->form_validation->set_message('user_email_check', "Email already exists");
        
        return $this->user_model->exists($user_email);
    }
    
    public function thumbnail($user_id=null){
        if($user_id != null){
            $thumbnail = $this->user_model->thumbnail($user_id);
            header("Content-type: {$thumbnail->user_thumbnail_type}");
            echo $thumbnail->user_thumbnail;
        }
    }
    
}
#2

[eluser]Flemming[/eluser]
I'm guessing that your callback needs to return FALSE if it has failed. You can return the $user_email inside the set_message rather than at the end of the function ...

Code:
$this->form_validation->set_message('user_email_check', 'The email' . $user_email . ' already exists');

?
#3

[eluser]flaky[/eluser]
Code:
return $this->user_model->exists($user_email);
yes, this returns either false or true depending if it finds the email

even if I change it to
Code:
public function user_email_check($user_email){
        $this->form_validation->set_message('user_email_check', "Email already exists");
        
        return FALSE;
    }
just for testing purposes, it isn't validating at all, this callback function isn't being called at all, it continues as if the validation has been successful, I have no clue why.
#4

[eluser]Flemming[/eluser]
hmmmm... are you using HMVC (modules) by any chance?
#5

[eluser]flaky[/eluser]
yes
#6

[eluser]Flemming[/eluser]
Ah! Then you need to do this:

Code:
if ($this->form_validation->run($this) == TRUE){

notice '$this' inside the run()

I can't remember why ... I just remember that I ran into exactly the same issue a while back and that was the solution!
#7

[eluser]flaky[/eluser]
it isn't working Sad
#8

[eluser]Flemming[/eluser]
which version of HMVC are you using?

can anyone else suggest a solution to Flaky's problem?
#9

[eluser]flaky[/eluser]
found the solution

http://www.mahbubblog.com/php/form-valid...deigniter/


thanks for your help Smile
#10

[eluser]Flemming[/eluser]
really sorry about that - I remember now that yes, I had to do exactly that in order to get it to work!

apologies for only giving you a part of the solution! Glad you got to the bottom of it in the end :-)




Theme © iAndrew 2016 - Forum software by © MyBB