⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

MY_Form_validation.php not working



endless_forms
  • profile picture
  • Member

Posted 05 May 2012 - 15:48 PM

Hi,

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');


web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 05 May 2012 - 16:30 PM

You have to go to [i]application/libraries/grocery_crud.php[/i] at around line 3733

and change the:


class grocery_CRUD_Form_validation extends CI_Form_validation{


to


class grocery_CRUD_Form_validation extends MY_Form_validation{

endless_forms
  • profile picture
  • Member

Posted 05 May 2012 - 17:53 PM

Cool! That worked.

Suvi
  • profile picture
  • Member

Posted 07 July 2013 - 13:08 PM

Sorry, it doesn't work for me:

 

In MY_Form_validation.php i have:

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

class MY_Form_validation extends CI_Form_validation {

	function __construct()
    {
        parent::__construct();
    }

    function valid_url($url)
    {
        $pattern = "\b((?#protocol)https?|ftp)://((?#domain)[-A-Z0-9.]+)((?#file)/[-A-Z0-9+&@#/%=~_|!:,.;]*)?((?#parameters)\?[A-Z0-9+&@#/%=~_|!:,.;]*)? ";
        return (bool) preg_match($pattern, $url);
    }
}

and I changed the line:

 

4520 class grocery_CRUD_Form_validation extends CI_Form_validation{

 

to

 

4520 class grocery_CRUD_Form_validation extends MY_Form_validation{

 

has anything more changed in the lastest version?

 

Fatal error: Class 'MY_Form_validation' not found in /blablabla/application/libraries/grocery_crud.php on line 4520


davidoster
  • profile picture
  • Member

Posted 08 July 2013 - 22:32 PM

Hello and welcome to the forums [member=Suvi].

Did you put your library under application/libraries?

Check also under application/config the file config.php if it has this line:

$config['subclass_prefix'] = 'MY_';