Welcome Guest, Not a member yet? Register   Sign In
Extending Form Validation
#1

[eluser]RaGe10940[/eluser]
I need more functionality from CI for student ID's so I want to create my own validation but it is not working period, with any condition. I feel like the function is not even being called.

This is my code :

Code:
<?php

if(!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Form_validation extends CI_Form_validation
{

   public function is_valid_student_id($str)
   {
  if(strlen($str > 9))
  {
    $this -> set_message('is_valid_student_id', 'A-Number can not be over 9 characters');
    return FALSE;
  }
  elseif(strlen($str < 9))
  {
    $this -> set_message('is_valid_student_id', 'A-Number can not be under 9 characters');
    return FALSE;
  }
  elseif((substr($str, 0, 1) !== 'a') || (substr($str, 0, 1) !== 'A'))
  {
    $this -> set_message('is_valid_student_id', 'A-Number must begin with "A"');
    return FALSE;
  }
  elseif(!preg_match("/^[0-9]/", $str))
  {
    $this -> set_message('is_valid_student_id', 'A-Number must have 8 digits 0 - 9');
    return FALSE;
  }
  else
  {
    return TRUE;
  }

   }

}

Is there anything I am missing?

and this is how I am calling it :
Code:
$this -> load -> library('form_validation');

  if(!$this -> input -> post('student') == 'yes')
  {
    $this -> form_validation -> set_rules('anum', 'A Number', 'required|is_valid_student_id|exact_length[9]');
  }
}
#2

[eluser]RaGe10940[/eluser]
In my logs file I am getting :

Code:
DEBUG - 2013-05-21 10:40:42 --&gt; Unable to find validation rule: is_valid_student_id

I am fairly confident that that MY_Form_validation is not being loaded.
#3

[eluser]TheFuzzy0ne[/eluser]
You didn't mention where your file resides.

It should be named MY_Form_validation.php and it should reside in ./application/libraries.
#4

[eluser]RaGe10940[/eluser]
Yes sorry, its there. Screen shot
#5

[eluser]RaGe10940[/eluser]
O...M...#....G!!!!!!!

My netbeans didn't add .php at the end of the file name -_- I hate life...That picture made me realize the problem
#6

[eluser]TheFuzzy0ne[/eluser]
Ha! Hitting Netbeans with a big hammer seems to do the trick. I've found that the bigger the hammer, the more effective it is.




Theme © iAndrew 2016 - Forum software by © MyBB