[eluser]RickP[/eluser]
[quote author="WanWizard" date="1282337361"]Form validation rules should only run after posting a form.[/quote]
Correct.
Quote:And only the correct form.
How does the library know which is the correct form?
Quote:If they run at any other time, you have a logic error in your code that needs corrected.
No, I don't think so.
Using the example from the docs, make the following changes:
First, in the controller (with validation rules) change index() to edit() and add a new
Code:
function index() {
$this->load->helper('form');
$this->load->view('validation_test');
}
and then create a validation_test.php view:
Code:
<p>Test with a <a href="<?=site_url('form/edit')?>">URL</a></p>
<p>Test with a <?=form_open('form/edit').form_submit('submit','Button').form_close()?></p>
If you click on the url, everything works as expected. However, if you click on the button the form displays with all the errors.
You can change the if statement in the edit function to:
Code:
if (count($_POST) < 2 || $this->form_validation->run() == FALSE)
all both the url and the button work as expected.