[eluser]TheFuzzy0ne[/eluser]
Hi everyone. I've been fighting with the form validation library for most of today. I've been trying to purify my HTML after calling a custom validation callback. In my mind, it should work, but in actuality, it doesn't. I've designed a simple test to illustrate what I'm talking about:
./system/application/controllers/test_form_validation
Code:
<?php
class Test_form_validation extends Controller
{
function index()
{
// Load the form validation library.
$this->load->library('form_validation');
// Set the rules.
$this->form_validation->set_rules('input', '', 'ltrim|callback__my_callback|rtrim');
// Run validation.
$this->form_validation->run();
// Output the page.
$this->output->set_output($this->get_view(TRUE));
}
function _my_callback()
{
// We'll just return TRUE so the test passes.
return TRUE;
}
function get_view()
{
return <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>Form validation test</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body>
<div>
<code>
content: "{$this->input->post('input')}"
</code>
</div>
<form action="" method="post">
<div>
<label>Input:
<input type="text" name="input" value=" some text " />
</label>
</div>
<div>
<input type="submit" name="submit" value="Submit" />
</div>
</form>
</body>
</html>
EOT;
}
}
In the case of the above, rtrim is never called. This is fixed if I make the field required, but this isn't a required field. Is this a bug, or am I missing something totally obvious here?