⚠ 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

An error has been occured at the insert



Julio
  • profile picture
  • Member

Posted 07 July 2013 - 13:49 PM

Hi guys,

 

I trying to use callback_before_insert like this:

$crud->callback_before_insert(array($this,'_callback_antes_insercao_validar_data'));
$crud->set_lang_string('insert_error','Data final não pode ser menor que inicial.');

callback:

function _callback_antes_insercao_validar_data($post_array)
	{
		if ((strtotime($post_array['DATFIM'])) < (strtotime($post_array['DATINI'])))
		{
			return false;
		}	
		return true;
	}

Instead of showing my set_lang_string custom message it shows "An error has been occured at the insert".

 

At the same way using callback_before_update it works fine as expected.

$crud->callback_before_update(array($this,'_callback_antes_atualizacao_validar_data'));
$crud->set_lang_string('update_error','Data final não pode ser menor que inicial.');

callback:

function _callback_antes_atualizacao_validar_data($post_array, $primary_key) 
	{
		if ((strtotime($post_array['DATFIM'])) < (strtotime($post_array['DATINI'])))
		{
			return false;
		}	
		return true;			
	}

Does anyone kwow what I am doing wrong?

How can I show my custom validation message using before insert callback?

 

Thanks in advance.


davidoster
  • profile picture
  • Member

Posted 08 July 2013 - 23:11 PM

Which version of Grocery CRUD are you using?


Julio
  • profile picture
  • Member

Posted 10 July 2013 - 10:57 AM

1.3.3

davidoster
  • profile picture
  • Member

Posted 10 July 2013 - 12:54 PM

Can you post the controller's code? Not everything, just the main function that calls the callbacks and the callbacks themshelves.


Julio
  • profile picture
  • Member

Posted 11 July 2013 - 01:56 AM

Thanks David for you reply.

 

My controller:

function periodos() {
	$crud = new grocery_CRUD();
	
	$crud->set_theme('datatables');
	$crud->set_table('e000per');
	$crud->set_subject('Período');
	$crud->unset_export();
	$crud->unset_print();

	$crud->display_as('DESPER','Descrição');
	$crud->display_as('DATINI','Data Inicial');
	$crud->display_as('DATFIM','Data Final');		
	$crud->display_as('PERFEC','Período Fechado');
	
	$crud->required_fields('DESPER','DATINI','DATFIM','PERFEC');

	$crud->callback_before_insert(array($this,'_callback_antes_insercao_validar_data'));
	$crud->set_lang_string('insert_error','Data final não pode ser menor que inicial.');

	$output = $crud->render();
	$this->template($output);	
}

function _callback_antes_insercao_validar_data($post_array)
{
	if ((strtotime($post_array['DATFIM'])) < (strtotime($post_array['DATINI'])))
	{
		return false;
	}	
	return true;
}

davidoster
  • profile picture
  • Member

Posted 11 July 2013 - 07:47 AM

Try to return $post_array; from your callback function.

Within your callback function you need to change (or not) something at the $post_array.