Welcome Guest, Not a member yet? Register   Sign In
Form Validation Config File Suddenly Only Works for Some Rules
#1

[eluser]Unknown[/eluser]
Update: I have found the error here it seems that the external form_validation setting do not work with greater_than[n].

The other fields I've tested seem to work fine. greater_than[n] works in the controller but not in the validation config file. For the purposes of my form I was able to replace it with is_natural_no_zero but I could image this would present issues in other forms!

Hi,

So I'm working on a project with numerous form and I've been working with a form validation config file but I'm having some issues.

The current form constantly gets the error:

"Unable to access an error message corresponding to your field name."

To be clear I am not using any custom callback on this form. The strange thing is if the only option in the form validation config is "Required" the error message shows up fine but as soon as I start adding extra parameters it shows that error.

I've stripped down the code to the simplest state to isolate this issue yet it still occurs.

Any help would be greatly appreciated.

This is truly mind boggling me since I'm fairly certain I've done everything correctly. Has anyone experienced anything similar? Also I should note that the form validation works great as soon as I copy it into the same document it just breaks if it's in the config file.

Here is the state I'm currently testing in:

View (the form)
Code:
<?php $this->load->view('header'); ?>
<form id="addclientone" class="uniform" method="post" action="<?php echo base_url(); ?>add_client/add/one"  >
                    <fieldset>
                        <legend>
                            General Details
                        </legend>
                        
                       &lt;?php echo validation_errors(); ?&gt;
                        <dl class="inline">
                        <dt><label for="number_of_clients">Number of Purchasers *</label></dt>
                            <dd>
                                <select name="number_of_clients" id="number_of_clients" class="small">
                                    <option value="1">1</option>
                                    <option value="2">2</option>
                                    <option value="3">3</option>
                                    <option value="4">4</option>
                                    <option value="5">5</option>
                                </select>
                            </dd>
                            
                            <dt><label for="condo_id">Select Community *</label></dt>
                            <dd>
                                 <select name="condo_id" id="condo_id" class="small">
                                    <option value="1">1</option>
                                    <option value="2">2</option>
                                    <option value="3">3</option>
                                    <option value="4">4</option>
                                    <option value="5">5</option>
                                </select>
                            </dd>
                            
                        </dl>
                          <div class="buttons">
                            <button type="submit" class="button">Begin</button>
                          
                        </div>
                    </fieldset>
                    &lt;/form&gt;
&lt;?php $this->load->view('footer'); ?&gt;

Controller
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Add extends CI_Controller {
    
    public function index()
    {
            $this->load->helper('form');
            $this->load->view('admin/alt_client');
    }
    
    function one() {
    
        $this->load->library('form_validation');
        
        $this->form_validation->set_error_delimiters('<div class="msg error">', '</div>');
        
        $post = $this->input->post();
            
            
        if($this->form_validation->run('clientone') == FALSE)
        {
            
            echo '&lt;html&gt;&lt;body><p>Here they are</p><p>';
            
            foreach($post as $k => $v) //this echos back everything fine
            {    
                echo $k;
                echo "<br>";
                echo $this->input->post($k);
                echo "<br><br>";
            }
            
            
            echo validation_errors();
            echo '</p>&lt;/body&gt;&lt;/html>';
        } else {
        
            //do this later
        }
        
            
    }

}

Form validation config (application/config/form_validation.php)

Please note I removed the extra forms due to their length but I have tested this config file like it is below.
Code:
$config = array(    
                
                        'clientone' => array(
                                    array(
                                            'field' => 'condo_id',
                                            'label' => 'Community',
                                            'rules' => 'trim|required|numeric|greater_than[0]|xss_clean'
                                         ),
                                    array(
                                            'field' => 'number_of_clients',
                                            'label' => 'Number of Clients',
                                            'rules' => 'trim|required|xss_clean' //this works but as soon as I add numeric back in it breaks!!!
                                         )    
                                )                  
               );


Messages In This Thread
Form Validation Config File Suddenly Only Works for Some Rules - by El Forum - 06-15-2011, 11:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB