• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pagination throws form validation error when clicking links

Using pagination library. Everything is working except when I click on one of the page links, it gets intercepted by the form validation library. Problem is it doesn't print anything, no errors nothing. Here is my controller:

function search_by_zip_result()
    $vehicle_type     = $this->input->post('vehicle_type_search');
    $vehicle_subtype  = $this->input->post('vehicle_subtype_search');
    $vehicle_make     = $this->input->post('vehicle_make_search');
    $vehicle_model    = $this->input->post('vehicle_model_search');
    $from_price       = $this->input->post('from_price');
    $to_price         = $this->input->post('to_price');
    $from_year        = $this->input->post('from_year');
    $to_year          = $this->input->post('to_year');
    $radius           = $this->input->post('radius');
    $zip              = $this->input->post('search_by_zip');

    $this->form_validation->set_rules('search_by_zip', 'Zip Code', 'trim|required|min_length[5]|max_length[5]|integer|xss');
    $this->form_validation->set_rules('from_price', 'Price From', 'trim|integer|xss');
    $this->form_validation->set_rules('to_price', 'Price to', 'trim|integer|xss');
    if($this->form_validation->run() == FALSE)
      echo 'error';
      echo validation_errors();

    $lat          = '';
    $lon          = '';
    $city         = '';
    $state        = '';
    $state_prefix = '';

    $lat_lon_rc = $this->_get_lat_long_zip($zip);
      foreach($lat_lon_rc->result() as $lat_lon_row )
         $lat           = $lat_lon_row->lat;
         $lon           = $lat_lon_row->lon;
         $city          = $lat_lon_row->city;
         $state         = $lat_lon_row->state_name;
         $state_prefix  = $lat_lon_row->state_prefix;

   $zips_in_radius = $this->zipcode_class->zipcodeRadius($lat, $lon, $radius);
     // Now get all the vehicles subimtted within those zip codes.    
    // Get the count of records for pagination
     $vehicle_result_count = $this->_get_vehicles_in_radius_zip($zips_in_radius,
                                                          $limit = null ,
                                                          $offset  = null);

       $config['base_url'] = base_url().'search/search_by_zip_result/';
       $config['total_rows'] = count($vehicle_result_count->result());
       $config['per_page'] = 3;
       $limit = $config['per_page'];
       $config['uri_segment'] = 4;
       $offset = $config['uri_segment'];
       $vehicle_result_2 = $this->_get_vehicles_in_radius_zip($zips_in_radius,  $vehicle_type, $vehicle_make, $vehicle_subtype, $vehicle_model,
                                                              $from_year, $to_year, $from_price,$to_price,
                                                              $limit, $offset);
       $subview['page_links'] = $this->pagination->create_links();
       $data['menu']              = $this->mylib->get_menu();
       $data['sidebar_content']   = $this->mylib->_load_sidebars();
       $data['page_header']       = 'Click on the ad to see details';
       $subview['search_results'] = $vehicle_result_2;
       $data['search_results']    = $this->load->view('search/results', $subview, TRUE);
       $this->load->view('welcome_message', $data);
               $this->session->set_flashdata('results_not_found', 'No results for those search criteria.' ));

     echo 'no zips codes ';

Why don't you bypass the validation if it is a click from page links?

How do you do that?

$this->form_validation->run() will return false on a normal page load, not just when POST values have been submitted. Your controller is done in a really weird order. It should be more like this:

if ($this->form_validation->run() === false)
    // A normal page load, or a form with errors goes here.
    // Valid form submitted, process it.

See the user guide example for more details.

It returns the error both ways. I suspect it has something to do with uri segment but I've tried all sorts of things

I think the problem is that the my query is too complicated to use the built in pagination. The pagination examples are for queries that grab one table with no parameters. The pagination does not carry over all of the parameters that I need for each click of the link.

The Pagination library has nothing to do with queries, complex or otherwise. You supply the data it uses to create links.

So I have learned. I'm building parameterized query links.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.