Hello I have 2 questions for this very very strange situation!

1 - I select some values from drop down (class, status, category) and leave some error in the form so it doesn't submit successfully, and press submit.

Surprisingly the form remembers the values for class, status and category and chooses the ones I selected correctly!!!!!!!Why am I surprised? Because print_r($selected_data); in view prints Array ( [class] => [category] => [status] => [price] => ) . Yes it has no values for any of these! How does it select the right ones? my_functions.php returns FALSE because it shows the validaiton errors on screen!

PHP Code:
public function search($recordstart=NULL)
    {
        
$this->load->library('my_functions');
        if(
$this->my_functions->validate_search())
            {
                
$search_data $this->my_functions->validate_search($record_start=0);
                
$this->session->set_userdata(array('search_data' => $search_data));
                
$this->session->userdata('search_data');
                
redirect(base_url('products/results'), 'location'301);
            }
        else
            {
                
$data $this->my_functions->validate_search();
                
$this->show_form($data);
            }
    }

protected function 
show_form($posted_data=NULL)
    {
        
$this->load->model('model_products');
        
$classes $this->model_products->list_classes();
        
$categories $this->model_products->list_categories();
        
$status $this->model_products->list_status();
        
$selected_data=array('class'=>$posted_data['class'], 'category'=>$posted_data['category'],'status'=>$posted_data['status'],'price'=>$posted_data['price']);
        
$data = array('selected_data'=>$selected_data'url'=>base_url(''), 'classes'=>$classes'statuses'=>$status,'categories'=>$categories,'selected_data'=>$selected_data,'header'=>'Search For Products','price_type'=>$this->price_type);
        
$this->load->view('product_search_form'$data);    
    } 
my_functions.php
PHP Code:
public function validate_search()
    {
        echo 
"Validation called";
        
$CI =& get_instance();
        
$CI->price_type=$CI->input->post('price_type');
        
$data['class'] = $CI->input->post('class') ? $CI->input->post('class') : '';
        
$data['category'] = $CI->input->post('category') ? $CI->input->post('category') : '';
        
$data['status'] = $CI->input->post('status') ? $CI->input->post('status') : '';
        
$data['price'] = $CI->input->post('price') ? $CI->input->post('price') : '';
        
        
$CI->load->library('form_validation');
        
$CI->form_validation->set_rules('class''Product Class''exact_length[1]|required|numeric|xss_clean|valid_product_class');
        
$CI->form_validation->set_rules('category''Product Category''exact_length[1]|required|alpha|xss_clean');
        
$CI->form_validation->set_rules('status''Product status''exact_length[1]|required|numeric|xss_clean');
        
$CI->form_validation->set_rules('price''Product Price''required|numeric|xss_clean|numeric|greater_than[0]');
        if (
$CI->form_validation->run())
            {
                return 
$data;    
            }    
        else
            {
                return 
FALSE;
            } 
View
Code:
<?php echo form_open(base_url('products/search'));
	print_r($selected_data);?>
    <table>
    	<tr>
        	<td>Class</td>
            <td colspan="2">
                <select name="class" class="search_drop_down">
                    <option value="all">All</option>
                    <?php foreach ($classes as $class):?>
                    <?php
					$selected = FALSE;
					if($selected_data['class']==$class){ $selected=TRUE;}?>    	
                        <option value="<?php echo $class->class;?>" <?php echo set_select('class', $class->class, $selected); ?>>&nbsp;<?php echo $class->class;?></option>
                    <?php endforeach;?>
                </select>
        	</td>
        </tr>
        <tr>
        	<td>Category</td>
            <td colspan="2">
                <select name="category" class="search_drop_down">
                    <option value="all">All</option>
                    <?php foreach ($categories as $category):?>
                    <?php 
					$selected = FALSE;
					if($selected_data['category']==$category){  $selected=TRUE;}?>    	
                        <option value="<?php echo $category->category;?>" <?php echo set_select('category', $category->category, $selected); ?>>&nbsp;<?php echo $category->category;?></option>
                    <?php endforeach;?>
                </select>
        	</td>
        </tr>...
And question 2:
Why does it print "Validation called" twice on screen?

Thanks forum