Welcome Guest, Not a member yet? Register   Sign In
codeigniter 1.7.2 hmvc and form_validation callback
#1

[eluser]prestondocks[/eluser]
Hi All,

I understand that there is a bug when using a callback function with HMVC and there is a hot fix for this issue. I have applied the hot fix by using the My_Form_validation.php documented on a number of sites.


I am using codeigniter1.7.2 and callback is not working for me. The callback function is not being called at all. At this point I am pulling my hair out. Could someone check the code below and let me know if I am doing something silly. All other validation rules are working.


This is the function that should contains the callback.
Code:
function profile()
    {

        
        if(!$this->input->post('submit'))
        {
            $view_data = array(
            'page_title' => 'User Profile',
            'content_file' => 'profile',
            'form_data' => $this->users_model->get_user($this->session->userdata('username')),
            );
            $this->load->view('themes/default/index.php',$view_data);
        }
        else
        {
            
            $this->form_validation->set_rules('username','Username','required|callback_username_check');
            $this->form_validation->set_rules('firstname','First name','required');
            $this->form_validation->set_rules('lastname','Last name','required|min_length[3]|max_length[20]');
            $this->form_validation->set_rules('email','Email','required|valid_email');
            if ($this->form_validation->run($this)==FALSE)
            {
                
                $view_data = array(
            'page_title' => 'User Profile',
            'content_file' => 'profile',
            );
                $this->session->set_flashdata('error','Please correct the errors');
                $this->load->view('themes/default/index.php',$view_data);
            }  
            else
            {  
            $this->users_model->update_profile();
            $userdata = $this->users_model->get_user($this->input->post($this->input->post('username')));
            $this->session->set_userdata($userdata);
            redirect('users/profile');
            }
        }
    }

This is the call back function. I have put a return false on the first line but it still does not work.
Code:
function username_check($str)
    {
            return false;
            $this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');
            return $this->users_model->username_unique($str);
    }
#2

[eluser]mi6crazyheart[/eluser]
I think the problem is in u'r callback function. Try this piece of code...

Code:
function username_check($str)
    {
        $sql = "SELECT COUNT(*) AS count FROM table_name WHERE UserLogin = ? "; // UserLogin= table field where u r storing u'r username
        $binds = array($_POST['username']);
        $query = $this->db->query($sql, $binds);
        $row = $query->row();

        if ($row->count != 0)
        {
            $this->form_validation->set_message('username_check', 'This Login name is all ready exist. Choose a new one');
            return FALSE;
        }
        
    }
#3

[eluser]prestondocks[/eluser]
Thanks for the reply MI6

The problem is that the function is not being called in the first place.

You will see that the first line of my function is
Code:
return false;

This was to try and force a false return in case my database call was faulty. The form just ignores it and continues processing, but does respond to all other rules.
#4

[eluser]danmontgomery[/eluser]
Is the callback a member of the same controller as profile() or an extension of the form_validation class?
#5

[eluser]prestondocks[/eluser]
All methods are in the same class.
#6

[eluser]matt_a[/eluser]
I'm curious if the OP came up with a solution. I'm having the same exact problem.

I've applied the fix that has been mentioned all over (creating the MY_Form_validation.php), and my callback function is not being called.


I've spent hours trying to figure this out.
#7

[eluser]matt_a[/eluser]
:red:

I'm not sure how much of a "newbie" mistake this is, but when applying the fix, I was placing MY_Form_validation.php in /system/libraries rather than /system/application/libraries. Moving the file into the application libraries folder fixed the issue.

I hope this can help the OP or anyone else having this problem.




Theme © iAndrew 2016 - Forum software by © MyBB