⚠ 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

How to show callback_before_delete custom error message?



wdsandeep
  • profile picture
  • Member

Posted 29 September 2012 - 02:31 AM

I want to check parent category in list. and if found it shows error message that you can't delete record until deleted related product or category... I have done all conditions but don't know how to show custom error message..


public function category_callback_before_delete($primary_key)
{

//check as parent category
$error = check_parent_category(); // it return true or false

if($error) {
$this->form_validation->set_message('category_callback_before_delete', 'The username already exists');
return false;
}
else
{
return true;
}
}

Vinsensius Angelo
  • profile picture
  • Member

Posted 24 October 2013 - 07:12 AM

i have same problem, the documentation (http://www.grocerycrud.com/documentation/options_functions/callback_before_delete

 

) doesn't explain how to add custom error message.
 


Nayosx Ness
  • profile picture
  • Member

Posted 03 September 2015 - 17:24 PM

Use $crud->set_lang_string('delete_error_message', 'My message for delete on error');

 

This on declaration for you $crud 

 

(Siento mucho mi ingles y el estar respondiendo 3 años despues jajaja)


Json Sean
  • profile picture
  • Member

Posted 01 November 2017 - 05:34 AM

/topic/2109-error-messages/#entry15705

 

 

Here is the way to custom error message when editing :

 

1、modify Grocery_CRUD.php

protected function db_update($state_info)
{

...

if($this->callback_before_update !== null)
{
$callback_return call_user_func($this->callback_before_update$post_data$primary_key);

if(!empty($callback_return) && is_array($callback_return))
{
$post_data $callback_return;
}
elseif($callback_return === false)
{
return false;
}elseifis_string($callback_return))
{
return array('status' => false,'message' => $callback_return);
}


}

 

...

 

}

 

 

 

 

protected function update_layout($update_result false$state_info null)

{
@ob_end_clean();
if($update_result === false)
{
echo json_encode(array('success' => $update_result));
}elseif(isset($update_result['status'])){
//TODO:custom error
$error_message '<p>'.$update_result['message']. '</p>';
echo json_encode(array(
'success' => $update_result['status'] ,
'error_message' => $error_message,
));
}

else
{

 

...

 

}

 

2、edit.js

 

...

 

$('#crudForm').ajaxSubmit({

dataType'text',
cache'false',
beforeSendfunction(){
$("#FormLoading").show();
},
successfunction(result) {
data = $.parseJSON(result);
if (data.success) {

if(save_and_close)
{
if ($('#save-and-go-back-button').closest('.ui-dialog').length === 0) {
window.location = data.success_list_url+'?type=edit';
//form_success_message(data.success_list_url);
else {
$(".ui-dialog-content").dialog("close");
success_message(data.success_message);
}

return true;
}

form_success_message(data.success_message);
}else if (!data.success & data.error_message != null){
//TODO:custom error message
form_error_message(data.error_message);
else {
form_error_message(message_update_error);
}
},
errorfunction(){
form_error_messagemessage_update_error );
}
});

...

 

3、in you callback function, just return the string of your error message:

 

function before_xxx_update_callback($post_array$primary_key) {

if( error ){
$message 'error message';
return $message;
}

return $post_array;

}

 

 

To make it extendibility , you may define Cutom_Grocery_CRUD.php extending Grocery_CRUD.php , then modify Cutom_Grocery_CRUD.php.