Jump to content


Json Sean

Member Since 14 Sep 2017
Offline Last Active Dec 27 2017 09:16 AM
-----

Posts I've Made

In Topic: Error Messages

01 November 2017 - 05:36 AM

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;
+   }elseif( is_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',
  beforeSend: function(){
    $("#FormLoading").show();
  },
  success: function(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);
  }
 },
 error: function(){
   form_error_message( message_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.


In Topic: Error management in callback_update

01 November 2017 - 05:35 AM

https://www.groceryc...ges/#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;
+ }elseif( is_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',
beforeSend: function(){
$("#FormLoading").show();
},
success: function(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);
}
},
error: function(){
form_error_message( message_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.

 

In Topic: How to show callback_before_delete custom error message?

01 November 2017 - 05:34 AM

https://www.groceryc...ges/#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.

 

In Topic: how to show custom error message after callback_before_insert

01 November 2017 - 05:33 AM

https://www.groceryc...ges/#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.

 

In Topic: Set Custom Message Validation (CALLBACK BEFORE INSERT)

01 November 2017 - 05:32 AM

https://www.groceryc...ges/#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.