Welcome Guest, Not a member yet? Register   Sign In
Problems extending the Form_validation (CI 1.7)
#1

[eluser]Nonox[/eluser]
Hi.
I have some problems extending the new Form_validation, I followed the same process that I did with CI 1.6.3, below is the code example:

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

class MY_Form_validation extends CI_Form_validation {

    function MY_Form_validation()
    {
        parent::CI_Form_validation();
    }

    function test($str)
    {
        return FALSE;
    }
}
// END Validation Class
?>

How you can see is simple, but nothing happen, someone knows if I'm doing something wrong?
#2

[eluser]OES[/eluser]
Hello

All looks good to me but I did have a problem extending due to me using a config file to hold my form arrays.

See my post here.

http://ellislab.com/forums/viewthread/97063/

Also if you are looking to use the constructor you will need to do this.

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

class MY_Form_validation extends CI_Form_validation {

  var $CI;    
  function MY_Form_validation($config = array())
    {
        parent::CI_Form_validation($config);
        $this->CI = get_instance();
        $this->CI->load->helper('url');
                // etcetc

    }

Hope this helps.
#3

[eluser]xwero[/eluser]
OES the $CI variable is defined in the parent class so you don't have to add it to the extended class.
#4

[eluser]Nonox[/eluser]
Hi, first of all thanks for your advice.

I tried with this:

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

class MY_Form_validation extends CI_Form_validation {

  function MY_Form_validation($config = array())
  {
      parent::CI_Form_validation($config);
      $this->CI = get_instance();
      $this->CI->load->helper('url');
  }

  function test($str)
  {
      return FALSE;
  }

}
?>

But nothing happened, the core validations works fine, but my extension doesn't exist for CI.
#5

[eluser]xwero[/eluser]
How did you check it?
#6

[eluser]Nonox[/eluser]
Well, I have an entry in my array language like this:

Code:
$lang['test'] = "%s ?.";

And... in my controller:

Code:
$this->form_validation->set_rules('fecha_nac', 'lang:adm_form_usuarios_modificar_campFecha', 'trim|required|exact_length[10]|xss_clean|test');

And... in my view:

Code:
<input name="fecha_nac" value="<?php echo set_value('fecha_nac',$fecha_nac);?>" class="input-text" type="text" maxlength=10>
<?php echo form_error('fecha_nac'); ?>


These validations works fine:
Code:
trim|required|exact_length[10]|xss_clean
#7

[eluser]xwero[/eluser]
And what was the value you tested it with?

Also try testing it with less rules, the other rules only add more things to be aware of while testing.

Additionally you should check if the test in the language key is the value you added to the file. maybe you have the test key in another language file?


You can remove the $this->CI lines they have no function in you case.
#8

[eluser]Nonox[/eluser]
I found the mistake, I had written in a bad way the name of the file.

Bad... MY_form_validation.php

Good... MY_Form_validation.php

Conclusion:

This is the way:

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

class MY_Form_validation extends CI_Form_validation {

  function MY_Form_validation($config = array())
    {
      parent::CI_Form_validation($config);
      $this->CI = get_instance();
    }
}
?>

And don't forget to write the name of the file respecting the capital letters.

OES and xwero.
Thank you very much!!




Theme © iAndrew 2016 - Forum software by © MyBB