[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:
<?php echo form_open(' ','id="login"');?>
character name<br />
<input type="text" name="char" id="char"><br />
<?php echo form_error('char');?>
password<br />
<input type="password" name="pass" id="pass"><br />
<?php echo form_error('pass');?>
<input type="submit" value="login" name="log"><br />
<span style="font-size:11px;">
<?php echo anchor('register/get_chars','register'); ?>
<a href="rpass">retrieve password</a>
</span>
</form>
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]<?php echo form_error('char_check');?> on the view but still the same.
What the hell am i doing wrong.
Cheers