[eluser]TheFuzzy0ne[/eluser]
You wouldn't. You'd just load the view again, and you keep reloading the view whilst the validation is failing. When the validation passes,
then you do the redirect.
./system/application/controllers/validation_example.php
Code:
class Validation_example extends Controller {
function index()
{
$this->load->library('form_validation');
if ($this->input->post('submit') && $this->_run_validation())
{
die('The validation has passed, so we redirect');
}
# Load the view as the form is either not being submitted, or validation hasn't passed.
$this->load->view('validation_example');
}
function _run_validation()
{
$this->form_validation->set_error_delimiters('', '');
$this->form_validation->set_rules(
'text_input',
'Text Input',
'required|alpha'
);
return $this->form_validation->run();
}
}
./system/application/views/validation_example.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html >
<head>
<title>Form Validation Example</title>
</head>
<body>
<form action="/validation_example" method="post">
<div>
<label>Text Input:
<span style="color:red; font-weight: bold;"><?php echo form_error('text_input'); ?></span><br />
<input type="text" name="text_input" value="" />
</label>
</div>
<div>
<input type="submit" name="submit" value="Validate" />
</div>
</form>
</body>
</html>