CodeIgniter Forums
extending form_validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: extending form_validation (/showthread.php?tid=27401)



extending form_validation - El Forum - 02-09-2010

[eluser]Unknown[/eluser]
Hello- I've been looking around the forum and I'm sure the answer to my problem is in here somewhere but I just can't find it. I have the following, leaving out (I think) code that isn't really necessary to the general idea, set up to see if I could get anything at all to load from my extended library- I cannot... It seems to me that this should just stop the form cold- but it doesn't, it submits every time:

system/libraries/MY_form_validation.php
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_my_function() {
    return false;
    }
}

system/application/controllers/signup.php
Code:
<?php
class Signup extends Controller {
    
    function Signup() {
        parent::Controller();
        $this->load->library('form_validation');
    }

    function index() {
        $this->form_validation->set_rules('email', 'Email Address', 'test_my_function');
    if ($this->form_validation->run() == FALSE) {
            $this->load->view('signup_view', $data);
    } else {
            // here's where stuff happens as a result of filling out the form, probably not important- it works...
            $this->load->view('submit_view', $display);
    }
    }

I've tried 4 or 5 different functions inside MY_form_validation.php, nothing I do seems to call them into my controller... am I missing something really obvious?

thanks in advance-


extending form_validation - El Forum - 02-09-2010

[eluser]tomcode[/eluser]
1. I have my extending libraries under application/libraries, never tried having them in the system
2. the file name should be MY_Form_validation.php, not MY_form_validation.php
3. put a log message in the constructor of MY_Form_validation, them You're sure whether the file is loaded
4. the method test_my_function() should take one parameter (the value to validate), i.e. test_my_function($value)


extending form_validation - El Forum - 02-10-2010

[eluser]Unknown[/eluser]
Thanks, it was the directory- moved the file MY_Form_validation.php from system/libraries/ to to system/application/libraries/ and all functions are loading smoothly... Thank you!