Welcome Guest, Not a member yet? Register   Sign In
SOLVED: form validation set_message() going nuts "Unable to access an error message corresponding to your field name." e
#1

[eluser]atno[/eluser]
controllers/welcome.php

Code:
public function index()
    {
            $this->load->library('form_validation');

            $val = $this->form_validation;
            $val->set_error_delimiters('<div class="error">', '</div>');
            $val->set_rules('char','character name','trim|required|alpha_numeric|callback_char_check');
            $val->set_rules('pass','password','trim|required|alpha_numeric|min_length[5]|max_length[10]|callback_pass_check');
            
            if($val->run() == FALSE){
                $val->set_message('char_check','Not a registered charname.');
            }
            
            $data['main_content'] = 'welcome_message';
            $this->load->view('includes/template',$data);
    }

        
        function char_check() {
            $char = $this->input->post('char');
            $query = $this->db->get_where('characters', array('characterName' => $char), '1');
            echo $query->num_rows();

            if($query->num_rows() == 0){
                return false;
            }

            return true;
        }

views/welcome_message.php

Code:
&lt;?php echo form_open(' ','id="login"');?&gt;
            character name<br />
            &lt;input type="text" name="char" id="char"&gt;&lt;br />
            &lt;?php echo form_error('char');?&gt;
            password<br />
            &lt;input type="password" name="pass" id="pass"&gt;&lt;br />
            &lt;?php echo form_error('pass');?&gt;
            &lt;input type="submit" value="login" name="log"&gt;&lt;br />
            <span style="font-size:11px;">
                &lt;?php echo anchor('register/get_chars','register'); ?&gt;
                <a href="rpass">retrieve password</a>
            </span>
        &lt;/form&gt;

So when i just click the submit button i normally get the errors "The character name field is required" and "The password field is required.". But when i enter a name on character name and character name doesnt exists on database i get "Unable to access an error message corresponding to your field name."

I tried to add [code]&lt;?php echo form_error('char_check');?&gt; on the view but still the same.

What the hell am i doing wrong.

Cheers


Messages In This Thread
SOLVED: form validation set_message() going nuts "Unable to access an error message corresponding to your field name." e - by El Forum - 05-11-2011, 08:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB