I created some custom validation rules and added them to libraries/MY_Form_validation.php, but grocery crud does not seem use the rules in MY_Form_validation.php.
I prefer not using callback functions because I want to use these rules on multiple controllers, and I didn't want to write them in every controller.
MY_Form_validation.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Form_validation extends CI_Form_validation {
function __construct($config = array()) {
parent::__construct($config);
}
function valid_url($data) {
$pattern = "/^http(|s):\/{2}(.*)\.([a-z]){2,}(|\/)(.*)$/i";
if(preg_match($pattern, $data)) {
if(filter_var($data, FILTER_VALIDATE_URL)) {
return true;
}
}
$this->CI->form_validation->set_message('is_valid_url', 'The %s must be a valid URL');
return false;
}
controller/xxxx.php
$crud->set_rules('url', 'url','valid_url');