[eluser]musonic[/eluser]
I'm having a problem with form validation. I've used it loads of times before (on this application and many others) and just can't see why I can't get it to work this time. The validation itself seems to be working ie it will return false if the criteria aren't met and true if they are, but for some reason when it returns false the validation_errors() method simply returns an empty string.
Here is the code:
Controller:
Code:
public function add_contacts()
{
if($this->input->post('contact_search')&&$this->form_validation->run('contact_search'))
{
// send form data to seach function
$this->_find_contacts($this->input->post('contact_search'));
}
elseif($this->input->post('contact_upload'))
{
$this->_upload_contacts($this->input->post('contact_upload'));
}
else {
// render display
$this->template->title('Add Contacts')
->set('page_name', 'contacts')
->set('body', 'add_contacts')
->set_partial('contact_search', 'partials/contact_search')
->set_partial('upload_contacts', 'partials/upload_contacts')
->build('add_contacts');
}
}
View:
Code:
<?php
echo form_open(base_url().'contacts/add_contacts', array('class'=>'standard_form'));
?>
<div class="info">
<div class="heading"><label for="contact_search">Search by name:</label></div>
<div class="element"><?php echo form_error('contact_search');?><input type="text" name="contact_search" />
<?php echo form_submit(array('name'=>'submit','class'=>'small_button'), 'search'); ?>
</div>
</div>
<?php
echo form_close();
I know that at the moment I haven't sent any errors to the template function in the controller, so obviously no errors will be displayed, but if you do a test for what validation_errors() returns then you will see that it returns an empty string. eg:
[code]
var_dump(validation_errors());