04-11-2011, 07:08 AM
[eluser]Neerav[/eluser]
Hello Guys,
I am using codeigniter version 2.0.
I have followed this instruction to extend core form validation library.
I try placing my new file named 'MY_Form_validation.php' inside 'application/libraries' and 'application/core' directory respectively. But neither one is working for me. I can not get my valid_url function working. Following is the content of my 'MY_Form_validation.php' file,
I am loading form validation library in my controller and default validation methods are working fine.
Please advise me what's wrong with this or am I missing any steps.
Thanks in advance.
Regards,
Neerav
Hello Guys,
I am using codeigniter version 2.0.
I have followed this instruction to extend core form validation library.
I try placing my new file named 'MY_Form_validation.php' inside 'application/libraries' and 'application/core' directory respectively. But neither one is working for me. I can not get my valid_url function working. Following is the content of my 'MY_Form_validation.php' file,
Code:
<?php if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
/**
* MY_Form_Validation Class
*
* Extends Validation library
*
* Adds one validation rule, valid_url to check if a field contains valid url
*/
class MY_Form_validation extends CI_Form_validation
{
function __construct()
{
parent::__construct();
}
// --------------------------------------------------------------------
/**
* valid_url
*
* @access public
* @param field
* @return bool
*/
function valid_url($field)
{
$CI =& get_instance();
$CI->form_validation->set_message('valid_url', 'The %s field must contain a valid url.');
return (!preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $field)) ? FALSE : TRUE;
}
}
// end file
I am loading form validation library in my controller and default validation methods are working fine.
Please advise me what's wrong with this or am I missing any steps.
Thanks in advance.
Regards,
Neerav