Welcome Guest, Not a member yet? Register   Sign In
Custom SetRules LIBRARY
#1

[eluser]Unknown[/eluser]
Right sorry is this is a noob question but i've only recently began using CI (by which i am total surprised on how powerful this is).

I was wondering how do you go about adding form_validation rules. I'm not talking about callbacks. I want to add a custom library to "application/libraries" that way when upgrading CI it will still be a valid reference. Another reason for this is the usability of just typing in is_valid_date along with the likes of required|xss_clean etc. The main reason i want to do this besides being future proof is I need to use this validation in more than one controller (actually 5!).

How would I set this up?

I have tried creating a file in the library folder and typing
Code:
<?php
class newPHPClass extends CI_Form_validation {
//put your code here
function is_valid_date($str) {
    if (strlen($str) > 9 && strlen($str) < 11)
        return true;
    else
        return false;
}
}
?&gt;
and of course this in the controller
Code:
$this->form_validation->set_rules('to_date', 'To Date', 'required|is_valid_date|xss_clean');

        if ($this->form_validation->run() == TRUE){
(yes I have loaded the form_validation library)
but why is it not passing another back? do I need to put is_valid_date?
I haven't written my query yet but I have tried just to use strlen to make sure it's between two lengths




Theme © iAndrew 2016 - Forum software by © MyBB