Jump to content


Form Validation Callbacks not working with HMVC modular extention

form validation hmvc not working

  • Please log in to reply
11 replies to this topic

#1 arif_avi

arif_avi

    Member

  • Members
  • PipPip
  • 12 posts

Posted 10 May 2012 - 07:31 AM

Hello Jhonny,

Can you tell why the call backs in set rules not working if i am using HMVC extention?

here is my controller code.

<?php
/**
* Description of doctor
*
* @author Arif
*/
Class Doctor extends MX_Controller {
	function __construct() {
		parent::__construct();
		$this->load->database();
		$this->load->library("my_session");
		
		$this->my_session->checkSession();
	  
	  
	}
	  
	
	function appointment_slots()
	{
		$userid = (int)$this->uri->segment(3);
		if($userid <= 0):
			redirect(base_url());
			die();
		endif;
		
		$this->load->model("doctor_model");
		$doctor = new Doctor_model();
		
		$dinfo = $doctor->getDoctorInfo($userid);
		if(!$dinfo)
		{
			redirect(base_url());
			die();
		}	
		
		try{
			$this->load->library('grocery_CRUD');
			/* This is only for the autocompletion */
			$crud = new grocery_CRUD();
			
			$crud->unset_jquery();
			$crud->set_theme(TABLE_THEME);						
			
			$crud->set_table(TBL_APPOINTMENT_SLOTS);									
			$crud->set_subject('Appointment Slot');			
					  
			$crud->required_fields(array('day','startTime','endTime','numOfPatients','isActive'));
			$crud->columns('day','startTime','endTime','numOfPatients','isActive');
			$crud->display_as('day','Day')
				 ->display_as('startTime','Start Time')	
				 ->display_as('endTime','End Time')  
				 ->display_as('numOfPatients','Number Of Patients')
				 ->display_as('isActive','Active(1 = Active)');
		   
			$crud->set_rules("startTime", "Start Time", "xss_clean|trim|required");
			$crud->set_rules("endTime", "End Time", "xss_clean|trim|required|callback_checkAppointmentTime");
			$crud->set_rules("numOfPatients", "Number of Patients", "xss_clean|trim|required|integer");
			
			$time = time();
			$crud->add_fields('day','startTime','endTime','numOfPatients','isActive','userId','creationDtTm','updateDtTm');
			$crud->edit_fields('day','startTime','endTime','numOfPatients','isActive','userId','updateDtTm');
						
			$crud->change_field_type('creationDtTm', 'hidden', $time);
			$crud->change_field_type('updateDtTm', 'hidden', $time);		  
			$crud->change_field_type('userId', 'hidden', $dinfo->row()->userId);		  
			
			$output = $crud->render();
			$output->dinfo = $dinfo->row();		
			$output->userid = $output->dinfo->userId;
			$output->css = "";
			
			$this->load->library("my_functions");
			$output->js = "";
			$output->js .= $this->my_functions->addJs("ui/jquery-ui-1.8.18.custom.min.js");
			$output->js .= $this->my_functions->addJs("jquery.timepicker.min.js");
			
			$output->pageTitle = "Appointment Slots";
			$output->base_url = base_url();
			
			$output->body_template = "appointment_slots_index.php";
			$this->load->view("site_template.php",$output);			

		}catch(Exception $e){
			show_error($e->getMessage().' --- '.$e->getTraceAsString());
		}
		
	}
	
	function checkAppointmentTime()
	{		
		$starttime = $this->input->post("startTime",true);
		$endtime = $this->input->post("endTime",true);
		
		$sArray = explode(":",$starttime);
		$eArray = explode(":",$endtime);
				
		if($eArray[0] > $sArray[0])
		{
			$this->form_validation->set_message("checkAppointmentTime","The %s is greater than the Start time. Please use a valid time.");
			return FALSE;
		}
		
		if($eArray[0] == $sArray[0]) // hours same
		{
			if($eArray[1] <= $sArray[1]) // minutes same
			{
				$this->form_validation->set_message("checkAppointmentTime","The %s is equal to the Start time. Please use a valid time.");
				return FALSE;
			}			
		}
		return false;
	}
	
	
}

?>

The callback function checkAppointmentTime is not being called.

I also tried this by changing line 3733 of grocery_crud.php ->

class grocery_CRUD_Form_validation extends MY_Form_validation

still no use.

thanks

#2 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,151 posts
  • LocationLondon

Posted 12 May 2012 - 10:41 AM

Check this article I think you will find your answer about HMVC and callbacks http://www.mahbubblo...in-codeigniter/
Posted Image

#3 arif_avi

arif_avi

    Member

  • Members
  • PipPip
  • 12 posts

Posted 12 May 2012 - 04:12 PM

Jhonny,

https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home

The solution is already given here and it works perfectly.

But i think u need to assign it in the grocery library the same thing mentioned in the url above.

The validation works perfectly when not using Grocery.

Kindly check and inform me as i am not being able to use hmvc properly with grocery ..

thanks

#4 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,151 posts
  • LocationLondon

Posted 13 May 2012 - 09:28 AM

Ok and thanks for the link. I cannot figure out a quick solution right now but I assign it as an issue at github to have it log and take a look when I have more time ( https://github.com/s...-crud/issues/33 ).
Posted Image

#5 arif_avi

arif_avi

    Member

  • Members
  • PipPip
  • 12 posts

Posted 13 May 2012 - 06:26 PM

Thanks a lot.

in the mean time if i find a solution will certainly inform u.

#6 mit

mit

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 14 May 2012 - 03:28 AM

Hello!

1. http://www.mahbubblo...in-codeigniter/ - create MY_Form_validation

2. Edit the application/libraries/grocery_crud.php

Line 2456
add
protected $hmvc = null;

Line ~2532
public function __construct(){}

=>
public function __construct($hmvc = null)
{
$this->hmvc = $hmvc;
}

Line 3733
class grocery_CRUD_Form_validation extends CI_Form_validation{

=>
class grocery_CRUD_Form_validation extends MY_Form_validation{


Line 606 and 672:
if ($form_validation->run())
=>
if ($form_validation->run($this->hmvc))


3. In Class Doctor extends MX_Controller {
$crud = new grocery_CRUD();
=>
$crud = new grocery_CRUD($this);


#7 arif_avi

arif_avi

    Member

  • Members
  • PipPip
  • 12 posts

Posted 14 May 2012 - 05:42 AM

Hello mit,

Hello!

1. http://www.mahbubblo...in-codeigniter/ - create MY_Form_validation

2. Edit the application/libraries/grocery_crud.php

Line 2456
add

protected $hmvc = null;

Line ~2532
public function __construct(){}

=>
public function __construct($hmvc = null)
{
$this->hmvc = $hmvc;
}

Line 3733
class grocery_CRUD_Form_validation extends CI_Form_validation{

=>
class grocery_CRUD_Form_validation extends MY_Form_validation{


Line 606 and 672:
if ($form_validation->run())
=>
if ($form_validation->run($this->hmvc))


3. In Class Doctor extends MX_Controller {
$crud = new grocery_CRUD();
=>
$crud = new grocery_CRUD($this);



Did you see the official wiredesizn's post on this ?

https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home

Its a working fix. Kindly give some time and go through it and suggest.

thanks

#8 mit

mit

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 14 May 2012 - 07:27 AM

Ok.

application/libraries/grocery_crud.php
Line 2456
protected $hmvc;


Line ~2532

public function __construct(){}


=>

public function __construct($hmvc = null) { $this->hmvc = $hmvc; }


Replace

protected function form_validation()
{
if ($this->form_validation === null)
{
$this->form_validation = new grocery_CRUD_Form_validation();

if ($this->hmvc)
$this->form_validation->CI = $this->hmvc;

$ci = &get_instance();
$ci->load->library('form_validation');
$ci->form_validation = $this->form_validation;
}
return $this->form_validation;
}



In Controller extends MX_Controller {
$crud = new grocery_CRUD($this);


MY_Form_validation is Optional.

#9 arif_avi

arif_avi

    Member

  • Members
  • PipPip
  • 12 posts

Posted 15 May 2012 - 05:59 AM

mit,
excellent...:D

but one more problem...

Set message cannot set the message in the callback.
Unable to access an error message corresponding to your field name.

Ne solution for this

#10 arif_avi

arif_avi

    Member

  • Members
  • PipPip
  • 12 posts

Posted 15 May 2012 - 06:09 AM

mit,
extremely sorry.

The fix is working perfectly.

Thanks A lot.

#11 shadesoflight

shadesoflight

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 16 August 2012 - 09:45 PM

Hello!

Great tutorial. We just had trouble with the line numbers (see inline bold red comments):

Ok.

application/libraries/grocery_crud.php
Line 2456 <--- Line 2687

protected $hmvc;


Line ~2532 <--- Line 2696

public function __construct(){}


=>

public function __construct($hmvc = null) { $this->hmvc = $hmvc; }


Replace <--- Line 660
  
protected function form_validation()
{
if ($this->form_validation === null)
{
$this->form_validation = new grocery_CRUD_Form_validation();

if ($this->hmvc)
$this->form_validation->CI = $this->hmvc;

$ci = &get_instance();
$ci->load->library('form_validation');
$ci->form_validation = $this->form_validation;
}
return $this->form_validation;
}



In Controller extends MX_Controller {
$crud = new grocery_CRUD($this);


MY_Form_validation is Optional.

Hello!

1. http://www.mahbubblo...in-codeigniter/ - create MY_Form_validation

2. Edit the application/libraries/grocery_crud.php

Line 2456 <--- Line 2687
add

protected $hmvc = null;

Line ~2532 <--- Line 2696
public function __construct(){}

=>
public function __construct($hmvc = null)
{
$this->hmvc = $hmvc;
}

Line 3733 <--- Line 3993
class grocery_CRUD_Form_validation extends CI_Form_validation{

=>
class grocery_CRUD_Form_validation extends MY_Form_validation{


Line 606 and 672: <--- Line 642 // 708
if ($form_validation->run())
=>
if ($form_validation->run($this->hmvc))


3. In Class Doctor extends MX_Controller { <--- "Doctor" is the controller from which you're using Grocery CRUD.
$crud = new grocery_CRUD();
=>
$crud = new grocery_CRUD($this);



#12 tinchorton

tinchorton

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 01 April 2017 - 03:36 AM

Hello mit,




Did you see the official wiredesizn's post on this ?
 

https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home
Its a working fix. Kindly give some time and go through it and suggest.

thanks

 

well...... this is working for me.......

https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home

it is broken !!!!!! lcdm!      

This repository does not have wiki enabled.





Also tagged with one or more of these keywords: form validation, hmvc, not working

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users