Welcome Guest, Not a member yet? Register   Sign In
How to make validate data and pagelinks sessions get along SOLVED
#1

[eluser]alvaroeesti[/eluser]
Hello

I ve got a form that is sent for validation. Ok it works.

Then I have pagelinks for pagination that work on sessions and yes, they work too but they conflict with the validation function so I have to turn validation off, which of course, should not.

just a couple of lines from the validation set as an example. This is inside a validateData function.

Code:
$this->form_validation->set_rules('object', 'object', 'trim|max_length[40]|xss_clean', 'required');
$this->form_validation->set_rules('regions', 'regions', 'trim|max_length[40]|xss_clean', 'required');

Then, still within that function (validateData) I have the code that handles the pagination which works by getting the input from the webform and sends it to a function that it is in the Model, that holds all the session things.

Code:
$object = $this->getresults_m->object_handler($this->input->get_post('object', TRUE));

Here is one sample of one of the handlers

Code:
public function object_handler($object)
{
  if($object)
  {
   $this->session->set_userdata('object', $object);
   return $object;
  }
  elseif($this->session->userdata('object'))
  {
   $object = $this->session->userdata('object');
   return $object;
  }
  else
  {
   $object ="";
   return $object;
  }
  
  
}

I have got this handler inside the Model that does all the queries, including the ones for counting the number of rows for pagination etc

So, what happens? what happens is that this:

Code:
$config['base_url'] = site_url('getresults/validateData');
$config['total_rows'] = $total_filas;
$config['per_page'] = $limit;

every time the pagelink is clicked, the query is resent but it has to go through the validating function and this validating function, by default will say "false" if any of its rules for each control is violated. But because the data is not coming this time from the webform but from a pagelink clicked, it will always be false, even if you comment out all of the lines like the one below

Code:
$this->form_validation->set_rules('object', 'object', 'trim|max_length[40]|xss_clean', 'required');

As you see, the handler is fed from the form data directly
Code:
$object = $this->getresults_m->object_handler($this->input->get_post('object', TRUE));

so it cannot go into a separate function of its own, because the webform can only send it to one, and it is validateData. :/

I hope this is not too confusing...

======================

This was solved by: the_fuzzy_one, simply by checking if the form had been sent. If it had it would go through the checking. If it had not (because it comes from the sessions), the skips it. As simple and effective as that. Thanks to him!




Theme © iAndrew 2016 - Forum software by © MyBB