[eluser]naytro[/eluser]
my example code:
<?php
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
}
function _username_check($username)
{
if($username === "test")
{
$this->validation->set_message('username_check', 'The %s field can not be the word "test"');
return FALSE;
}
else
return TRUE;
}
function index()
{
$this->load->library('validation');
$this->load->helper(array('form', 'url'));
$this->validation->set_error_delimiters('', '');
$rules['username'] = "required|callback__username_check";
$this->validation->set_rules($rules);
$fields['username'] = 'username';
$this->validation->set_fields($fields);
if ($this->validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->output->set_output("ok");
}
}
}
?>
myform.php
<html>
<head>
<title>My Form</title>
</head>
<body>
<?=form_open(''); ?>
<?=$this->validation->username_error; ?>
<input type="text" name="username" value="<?=$this->validation->username;?>" size="50" />
<div><input type="submit" value="Submit" /></div>
</form>
</body>
</html>