Welcome Guest, Not a member yet? Register   Sign In
form_validation problem
#1

[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">&lt;?php echo form_error('contact_search');?&gt;&lt;input type="text" name="contact_search" /&gt;
        
        &lt;?php echo form_submit(array('name'=>'submit','class'=>'small_button'), 'search'); ?&gt;
</div>
    </div>

&lt;?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());
#2

[eluser]Sudz[/eluser]
Instead of

Code:
form_open(base_url().'contacts/add_contacts', array('class'=>'standard_form'));

Use this
Code:
form_open(site_url('contacts/add_contacts'), array('class'=>'standard_form'));
#3

[eluser]InsiteFX[/eluser]
You dont even need base_url or site_url!
Code:
&lt;?php echo form_open('contacts/add_contacts', array('class'=>'standard_form'));?&gt;

This is all in the CodeIgniter Users Guide.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB