Welcome Guest, Not a member yet? Register   Sign In
Ignored function in MY_Form_validation library
#1

[eluser]Geoffrey[/eluser]
I've got a couple of fields in a form that are required but only if another field has a certain value. I originally created a callback function that worked flawlessly except I couldn't privatise it and as such it was available via a url. I thought I'd try and extend the form validation class and put my function in there but I'm finding the function gets ignored if the fields are empty.

Is there anyway round this? Without have to rebuild the _execute function?

MY_Form_validation.php file is as follows...
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();
    }
    
    function hodcheck($str)
    {
        $regType = $this->CI->input->post("regType");
        if ($regType == "Student Registration")
        {
            if (empty($str))
            {
                $this->set_message('hodcheck', 'The %s field can not be empty for a student registration');
                return FALSE;
            }
        }
        return TRUE;
    }
}

... and my call in the controller...
Code:
$this->form_validation->set_rules('hod_name', 'HoD Name', 'trim|xss_clean|hodcheck');
$this->form_validation->set_rules('hod_email', 'HoD Email Address', 'trim|valid_email|xss_clean|hodcheck');


Messages In This Thread
Ignored function in MY_Form_validation library - by El Forum - 11-26-2008, 04:29 PM
Ignored function in MY_Form_validation library - by El Forum - 11-26-2008, 04:37 PM
Ignored function in MY_Form_validation library - by El Forum - 11-26-2008, 04:43 PM
Ignored function in MY_Form_validation library - by El Forum - 11-26-2008, 05:02 PM
Ignored function in MY_Form_validation library - by El Forum - 11-26-2008, 05:15 PM
Ignored function in MY_Form_validation library - by El Forum - 11-26-2008, 05:40 PM
Ignored function in MY_Form_validation library - by El Forum - 11-26-2008, 05:47 PM
Ignored function in MY_Form_validation library - by El Forum - 11-26-2008, 08:54 PM
Ignored function in MY_Form_validation library - by El Forum - 11-26-2008, 11:51 PM



Theme © iAndrew 2016 - Forum software by © MyBB