goFrendiAsgard / No-CMS

No-CMS, A CodeIgniter Based CMS Framework
299 stars 199 forks source link

Callback in set_rules not working in HMVC #72

Closed velsankar closed 10 years ago

velsankar commented 10 years ago

I am getting the error message "Unable to access an error message corresponding to your field name" when I set a custom validation rule using a callback in grocery crud's set_rules method. I widely read that this is a known problem with HMVC. The solutions given have not worked for me.

Code snippet: class Manage_Departments extends CMS_Priv_Strict_Controller {

protected $URL_MAP = array();

public function index()
    {
         .....
         $crud->set_rules('department_name','Department','callback_unique_check');
         ......
    }

   public function unique_check()
   {
         // for testing i removed the actual lines in this method and tried returning true/false and get the same above mentioned error message for both.
          return FALSE;
    }

}

Did anyone come across this while using No-CMS?

Could anyone help me out on this?

goFrendiAsgard commented 10 years ago

Well, try this one:

class Manage_Departments extends CMS_Priv_Strict_Controller {

    protected $URL_MAP = array();

    public function index()
        {
             .....
             $crud->set_rules('department_name','Department','callback_unique_check');
             ......
        }

       public function unique_check()
       {
             // for testing i removed the actual lines in this method and tried returning true/false and get the same above mentioned error message for both.
              $this->form_validation->set_message('unique_check', 'Department name must be unique');
              return FALSE;
        }
}

Reopen the issue if you still have problem doing this.

velsankar commented 10 years ago

@goFrendiAsgard

Thank you for your response.

I had tried what you had suggested. Still the same error message.

I also followed the below link. But it did not work. Probably, we need to do something more specific to No-cms or grocerycrud in addition to what is suggested in the link below.

http://www.mahbubblog.com/php/form-validation-callbacks-in-hmvc-in-codeigniter/

Any thoughts on the above?

goFrendiAsgard commented 10 years ago

Confirmed. I still can't figure it out. However, you might want to try using callback_before_insert and callback_before_edit

goFrendiAsgard commented 10 years ago

Hi. Finally, I've able to make it work without affecting the rest of the code: https://github.com/goFrendiAsgard/No-CMS/tree/8b6484c1a6651c197409e68c9386348d242950ee

Download the newest, and let me know if you still has problem using callback. Good luck :)

velsankar commented 10 years ago

Hi @goFrendiAsgard , Thank you so much. Will try this out tomorrow. I was about to use your earlier suggestion of callback_before_insert. And this update has come just in time I wanted. :-) Will update here after trying it out.

heruprambadi commented 8 years ago

i got the same error message too. Bug again ?

1nv4d3r5 commented 8 years ago

http://www.mahbubblog.com/php/form-validation-callbacks-in-hmvc-in-codeigniter/ This one worked for me.