CodeIgniter Forums
Please Help with Form Validation Hmvc - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: External Resources (https://forum.codeigniter.com/forumdisplay.php?fid=7)
+--- Forum: Addins (https://forum.codeigniter.com/forumdisplay.php?fid=13)
+--- Thread: Please Help with Form Validation Hmvc (/showthread.php?tid=63036)



Please Help with Form Validation Hmvc - Vimal - 09-18-2015

I am Using HMVC with Codeigniter 3.
I am trying to make custom validation callback function and its not working with HMVC.
I get solution from searching in google like.
PHP Code:
class MY_Form_validation extends CI_Form_validation {

    function 
run($module ''$group '')
    {
        (
is_object($module)) AND $this->CI = &$module;
        return 
parent::run($group);
    }



But its not working for me.
Help me


RE: Please Help with Form Validation Hmvc - Vimal - 09-21-2015

Any One?


RE: Please Help with Form Validation Hmvc - PaulD - 09-21-2015

I presume you are using WireDesigz HMVC. Assuming this, callbacks are an issue with it but easily soluble.

In the docs for HMVC it says that you need to :

Quote:When using form validation with MX you will need to extend the CI_Form_validation class as shown below,

Code:
<?php
/** application/libraries/MY_Form_validation **/
class MY_Form_validation extends CI_Form_validation
{
   public $CI;
}
before assigning the current controller as the $CI variable to the form_validation library. This will allow your callback methods to function properly.

You can read about it here in full: https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc

There are also lots of good examples to solve this: http://stackoverflow.com/questions/27923836/codeigniter-hmvc-callback-not-working

I hope this helps,

Best wishes,

Paul.


RE: Please Help with Form Validation Hmvc - wolfgang1983 - 10-08-2015

Make sure that this code below is in application/libraries/MY_Form_validation.php


PHP Code:
<?php

class MY_Form_validation extends CI_Form_validation {

    function 
run($module ''$group '') {
        (
is_object($module)) AND $this->CI = &$module;
        return 
parent::run($group);
    }

  


Second when using callbacks with HMVC must include $this variable as shown below.


PHP Code:
public function index() {

$this->load->library('form_validation');

$this->form_validation->set_rules('something''Something''required|callback_test');

// Must include $this variable 

if ($this->form_validation->run($this) == FALSE) {

} else {

}

}

public function 
test() {

$this->load->library('form_validation');

if (
$this->model_something->can_loggin() == TRUE) {

return 
TRUE;

} else {

$this->form_validation->set_message('test''Cannot Login');

return 
FALSE;

}