I am building a module for EE2 and I want to extend CI's form validation library. I also want a separate language file too, kept within my module's directory so it's separate from future EE updates.

I created a libraries folder within my module's folder within the third_party folder.

I named the file: My_Form_validation.php

&lt;?php defined('BASEPATH') OR exit('No direct script access allowed');

class MY_Form_validation extends CI_Form_validation {

    /**
     * Constructor
     *
     * @access  public
     */ 
    function __construct($rules = array())
    {   
        parent::__construct($rules);
    }

    public function is_valid($value)
    {
        $this-&gt;form_validation-&gt;set_message('is_valid', 'The %s field can not contain any spaces');
        return FALSE;
    }
}

$this-&gt;EE-&gt;form_validation-&gt;set_rules('short_name', 'Short name', 'required|max_length[30]|is_valid');


I set the rule in the mcp.module_name.php file, I also swapped out $this->EE->form_validation... with $this->CI->form_validation and nothing.

it is not erroring out, it just doesn't seem like it is loading it correctly.

I tried loading the my form validation library in the mcp.module_name.php constructor and it returns this error: Fatal error: Class 'CI_Form_validation' not found

I shouldn't have to load it since it should load along with the default form validation library.

Below is my constructor for the mcp.module_name.php file

public function __construct()
{
    $this-&gt;EE =&amp; get_instance();
    $this-&gt;CI =&amp; get_instance();
    $this-&gt;EE-&gt;config-&gt;load('config');
    $this-&gt;conf = $this-&gt;EE-&gt;config-&gt;item('restaurant_menu_defaults');
    $this-&gt;CI-&gt;load-&gt;helper('file');
    $this-&gt;EE-&gt;load-&gt;helper('html');
    $this-&gt;EE-&gt;load-&gt;model('restaurant_menu_model');
    $this-&gt;base = BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=restaurant_menu';
    $this-&gt;base_url = BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=restaurant_menu';
    $this-&gt;EE-&gt;cp-&gt;add_to_head('&lt;link rel="stylesheet" href="/themes/third_party/restaurant_menu/css/restaurant_menu.css" type="text/css" media="print, projection, screen" /&gt;');
    $this-&gt;base_short = 'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=restaurant_menu';
    $this-&gt;data['base_url_short'] = $this-&gt;base_short;
    $this-&gt;data['base_url'] = $this-&gt;base;
    $this-&gt;site_id = $this-&gt;EE-&gt;config-&gt;item('site_id');
    $this-&gt;EE-&gt;cp-&gt;set_breadcrumb($this-&gt;base, $this-&gt;EE-&gt;lang-&gt;line('Restaurant Menu'));

    // setup navigation
    $this-&gt;EE-&gt;cp-&gt;set_right_nav(array(
        'module_nav_home' =&gt; $this-&gt;base_url.AMP.'method=index',
        //'module_nav_settings' =&gt; $this-&gt;base_url.AMP.'method=settings',
    ));
}


UPDATE:

added this to my construct on mcp.module_name

$this->EE->load->library('form_validation');
$this->EE->load->library('MY_Form_validation');

then in my methods, I run the form validation using: if($this->EE->my_form_validation->run() === FALSE)

Then I set my form field rules:

$this->EE->my_form_validation->set_rules('title', 'title', 'required|max_length[75]');
$this->EE->my_form_validation->set_rules('short_name', 'Short name', 'required|is_valid|max_length[30]');
$this->EE->my_form_validation->set_error_delimiters('', '');

MY_Form_validation.php

&lt;?php defined('BASEPATH') OR exit('No direct script access allowed');

class MY_Form_validation extends EE_Form_validation {

    /**
     * Constructor
     *
     * @access  public
     */ 
    function __construct($rules = array())
    {   
        parent::__construct($rules);
        $this-&gt;EE =&amp; get_instance();
    }

    public function is_valid($value)
    {
        $this-&gt;EE-&gt;form_validation-&gt;set_message('is_valid', 'The %s field can not contain any spaces');
        return false;
    }

}


It won't post the form unless all the rules are met, but it won't display the form error messages, why do you think that is?


Question: Adding parent_id attribute value in model
Answer: Even if parent_id is a column in the main table, you still need it as an attribute in the eav_attribute table.
Just create one attribute called parent_id (the same as the column) with the backend_type "static".  

This is how it works for the sku attribute for products.