⚠ 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

Form Validation Callbacks not working with HMVC modular extention



arif_avi

arif_avi
  • profile picture
  • Member

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

web-johnny

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

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/

arif_avi

arif_avi
  • profile picture
  • Member

Posted 12 May 2012 - 16: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

web-johnny

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

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/scoumbourdis/grocery-crud/issues/33 ).

arif_avi

arif_avi
  • profile picture
  • Member

Posted 13 May 2012 - 18:26 PM

Thanks a lot.

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

mit

mit
  • profile picture
  • Member

Posted 14 May 2012 - 03:28 AM

Hello!

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

2. [i]Edit the application/libraries/grocery_crud.php[/i]

Line 2456
add [php]protected $hmvc = null;[/php]
Line ~2532
[php]public function __construct(){}[/php]
=>
[php]public function __construct($hmvc = null)
{
$this->hmvc = $hmvc;
}[/php]
Line 3733
[php]class grocery_CRUD_Form_validation extends CI_Form_validation{[/php]
=>
[php]class grocery_CRUD_Form_validation extends MY_Form_validation{[/php]

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

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

arif_avi

arif_avi
  • profile picture
  • Member

Posted 14 May 2012 - 05:42 AM

Hello mit,

[quote name='mit' timestamp='1336966121' post='1733']
Hello!

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

2. [i]Edit the application/libraries/grocery_crud.php[/i]

Line 2456
add [php]protected $hmvc = null;[/php]
Line ~2532
[php]public function __construct(){}[/php]
=>
[php]public function __construct($hmvc = null)
{
$this->hmvc = $hmvc;
}[/php]
Line 3733
[php]class grocery_CRUD_Form_validation extends CI_Form_validation{[/php]
=>
[php]class grocery_CRUD_Form_validation extends MY_Form_validation{[/php]

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

3. In Class Doctor extends MX_Controller {
[php]$crud = new grocery_CRUD();[/php] => [php]$crud = new grocery_CRUD($this);[/php]
[/quote]


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

mit

mit
  • profile picture
  • Member

Posted 14 May 2012 - 07:27 AM

Ok.

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

Line ~2532

[php]public function __construct(){}[/php]

=>

[php]public function __construct($hmvc = null) { $this->hmvc = $hmvc; }[/php]

Replace
[php]
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;
}
[/php]


In Controller extends MX_Controller {
[php]$crud = new grocery_CRUD($this);[/php]

MY_Form_validation is Optional.

arif_avi

arif_avi
  • profile picture
  • Member

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

arif_avi

arif_avi
  • profile picture
  • Member

Posted 15 May 2012 - 06:09 AM

mit,
extremely sorry.

The fix is working perfectly.

Thanks A lot.

shadesoflight

shadesoflight
  • profile picture
  • Member

Posted 16 August 2012 - 21:45 PM

Hello!

Great tutorial. We just had trouble with the line numbers (see [b][color=#ff0000]inline bold red comments[/color][/b]):

[quote name='mit' timestamp='1336980436' post='1739']
Ok.

application/libraries/grocery_crud.php
Line 2456 [b][color=#ff0000]<--- Line 2687[/color][/b]
[php]protected $hmvc;[/php]

Line ~2532 [b][color=#FF0000]<--- Line 2696[/color][/b]

[php]public function __construct(){}[/php]

=>

[php]public function __construct($hmvc = null) { $this->hmvc = $hmvc; }[/php]

Replace [b][color=#FF0000]<--- Line 660[/color][/b]
[php]
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;
}
[/php]


In Controller extends MX_Controller {
[php]$crud = new grocery_CRUD($this);[/php]

MY_Form_validation is Optional.
[/quote]
[quote name='mit' timestamp='1336966121' post='1733']
Hello!

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

2. [i]Edit the application/libraries/grocery_crud.php[/i]

Line 2456 [b][color=#FF0000]<--- Line 2687[/color][/b]
add [php]protected $hmvc = null;[/php]
Line ~2532 [b][color=#FF0000]<--- Line 2696[/color][/b]
[php]public function __construct(){}[/php]
=>
[php]public function __construct($hmvc = null)
{
$this->hmvc = $hmvc;
}[/php]
Line 3733 [b][color=#FF0000]<--- Line 3993[/color][/b]
[php]class grocery_CRUD_Form_validation extends CI_Form_validation{[/php]
=>
[php]class grocery_CRUD_Form_validation extends MY_Form_validation{[/php]

Line 606 and 672: [b][color=#FF0000]<--- Line 642 // 708[/color][/b]
[php]if ($form_validation->run())[/php] => [php]if ($form_validation->run($this->hmvc))[/php]

3. In Class Doctor extends MX_Controller { [b][color=#FF0000]<--- "Doctor" is the controller from which you're using Grocery CRUD.[/color][/b]
[php]$crud = new grocery_CRUD();[/php] => [php]$crud = new grocery_CRUD($this);[/php]
[/quote]

tinchorton

tinchorton
  • profile picture
  • Member

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.