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

(This post was last modified: 09-08-2015, 12:14 AM by keulu.)

hi guys,

I had some troubles today with the form_validation lib, when i run the validation from a controller inside a folder

with an uri like that
Code:
/folder/controller/method
form_validation always return false in CI 3.0.1, everything work with the 3.0-dev or 3.0.0.

with an uri like that
Code:
/controller/method
, everything is ok too.

is that a bug ?
Reply
#2

Since most of my controllers are nested inside directories, I'm going to say no, but you probably need to show some code for anyone to be able to figure out what is happening in your case.
Reply
#3

(This post was last modified: 09-09-2015, 12:58 AM by keulu.)

here is my method from a controller named Groups.php on controllers/zabbix/Groups.php

PHP Code:
public function index()
{
 
$this->load->library('form_validation');
 if (
$this->session->has_userdata('group_search') || $this->form_validation->run('zabix_groups_search')) {
 
 if (
$this->form_validation->run('zabix_groups_search')){
 
$groups $this->group_model->GetGroupsWhere($where=array('name' => $this->input->post('group_search')));

 if (
count($groups) > && $this->input->post('group_search') != ""$this->session->set_userdata('group_search'$this->input->post('group_search'));

 }else{
 
$groups $this->group_model->GetGroupsWhere($where=array('name' => $this->session->has_userdata('group_search') ? $this->session->group_search ''));

 }
 }else{
 
$groups false;
 }
 
 
$this->data array_merge(compact('groups'), $this->data);
 
 
$this->load->view('zabbix/groups/index'$this->data);


as i said, $this->form_validation->run('zabix_groups_search') always return false, but $this->input->post('group_search') is ok


and this is my config for the validation



PHP Code:
'zabix_groups_search' => array(
            
    array(
 
     'field' => 'group_search',
 
     'label' => 'Recherche de groupe',
 
     'rules' => ''
 
   ),
        
 
 ), 
Reply
#4

I don't understand. That is the config for the validation? You mean that is what the file contains?
Reply
#5

no that's just a part of my array
Reply
#6

Are you using CI 3.0 or 3.0.1? There's a bug fix in 3.0.1 that allows empty rules, but the 3.0 version of the form validation library will always fail on an empty rule.
Reply
#7

that bug appear on CI 3.0.1 in my case.

everything work o CI 3.0.0 or CI 3.0-DEV
Reply
#8

sorry for disinter that topic, but i've found the problem.

if you submit a form and if you have a form_validation config file with your form entry in it,

Like that for example

PHP Code:
'zabix_groups_search' => array(

        array(
          
'field' => 'group_search',
          
'label' => 'Recherche de groupe',
          
'rules' => '',
        ),

        array(
          
'field' => 'search',
          
'label' => '',
          
'rules' => '',
        ),

      ), 

the form validation will fail, apparently because no one fields is required.

if i add the key "required" to my search (submit button) everythig works fine.

maybe an issue ?
Reply
#9

Well... I still don't understand why would you make a form validation rule without rules...
Reply
#10

yeah, my bad, that was a mistake.

But if I did that, maybe someone else will do the same one day Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB