Welcome Guest, Not a member yet? Register   Sign In
Unable to access an error message
#1

[eluser]Philo01[/eluser]
Hi there,

I have been trying to solve this problem for over 2 hours now, I searched for a solution but didn't find any that worked.
Somehow I keep getting the following message:

Quote:Unable to access an error message corresponding to your field name.

Code:
function validate_password_change(){
        
        $this->form_validation->set_rules('current_password', 'Current Password', 'trim|required|callback_password_match');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]');
        $this->form_validation->set_rules('password_match', 'Confirm Password', 'trim|required|matches[password]');
        
        if($this->form_validation->run() == FALSE){

            $this->change_password(); // This load the page where you can change your password the error message displays on that page.
            
        }else{
        
            echo 'Updated';
        
        }
    }
    
    function password_match($str)
    {

        if (md5($str) != $this->userlib->current_password())
        {
            $this->form_validation->set_message('current_password', 'Your old password is incorrect');
            return FALSE;
            
            }else{
            
            return TRUE;
        }
        
    }

It does call back to the password match function but it doesn't display the error message.
And my field really has that name:

Code:
<label for="current_password">Current Password</label>
&lt;?php echo form_password('current_password', null,'class="mediumField"'); ?&gt;

Anyone who can help me out Big Grin ?

Would really appreciate it! Getting crazy xD
#2

[eluser]BrianDHall[/eluser]
This might be too easy, but in your password_match function remove the if check - just set the form validation message and return false regardless. Still getting the error?

If not, you can always leave the set_message outside the loop anyway - you can set the message even if it is going to return true as error messages are only shown if the validation fails.

This is all inside a controller, right?
#3

[eluser]Philo01[/eluser]
[quote author="BrianDHall" date="1253600889"]This might be too easy, but in your password_match function remove the if check - just set the form validation message and return false regardless. Still getting the error?

If not, you can always leave the set_message outside the loop anyway - you can set the message even if it is going to return true as error messages are only shown if the validation fails.

This is all inside a controller, right?[/quote]

Thanks for your reply, I tried what you said but it didn't work Sad

Code:
function validate_password_change(){
        
        $this->form_validation->set_rules('current_password', 'Current Password', 'trim|required|callback_password_match');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]');
        $this->form_validation->set_rules('password_match', 'Confirm Password', 'trim|required|matches[password]');
        $this->form_validation->set_message('current_password', 'Your old password is incorrect');
        
        if($this->form_validation->run() == FALSE){

            $this->change_password();
            
        }else{
        
            echo 'Updated';
        
        }
    }
    
    function password_match($str)
    {

        if (md5($str) != $this->userlib->current_password()){
            return FALSE;
        }else{
            return TRUE;
        }
        
    }

I still get

Quote:Unable to access an error message corresponding to your field name.

Anyone else got a solution? Would really appreciate it!

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB