Jump to content


Error Messages


  • Please log in to reply
5 replies to this topic

#1 ineedhelp

ineedhelp

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 09 October 2013 - 02:09 PM

Hello admins and fellow users of grocery CRUD and CI.  I'm still a beginner.  HOw can I change the error messages (the errors there in the 1st pic) into something like the one in your registration form dear Admin (the second pic)? Can you help me? please. . .

Attached Thumbnails

  • error_error.jpg
  • reg_errors.JPG


#2 ineedhelp

ineedhelp

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 09 October 2013 - 03:25 PM

can someone help me with this one?  :unsure:



#3 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 10 October 2013 - 12:11 PM

Hi there,

 

Welcome to GC Forums,

 

Grocery crud dose an server side validation based on the rules defined.

 

Well the solution to your issue as i can suggest - this is purely done / managed by some client side library like jquery validator or so.

There are 2 ways to your solution

1 - use jquery validator (add the jquery validator script  - either by set_js / or by adding it to the theme if you plan to use it all place

- Create the required script that will control / configure your jquery validations in the form / manage the balloon display of errors add add it using set_js - that way before your form gets submitted - all error handling can be taken care @client level itself

 

2 - the ajax form submission and error handling is all the javascript functionality - u can deeply dug into the same and alter it as per your requirement (this is much tougher then the earlier one. Hence will recomend u go for the first solution)

 

Happy GCing :)



#4 ineedhelp

ineedhelp

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 10 October 2013 - 03:10 PM

Hi there,

 

Welcome to GC Forums,

 

Grocery crud dose an server side validation based on the rules defined.

 

Well the solution to your issue as i can suggest - this is purely done / managed by some client side library like jquery validator or so.

There are 2 ways to your solution

1 - use jquery validator (add the jquery validator script  - either by set_js / or by adding it to the theme if you plan to use it all place

- Create the required script that will control / configure your jquery validations in the form / manage the balloon display of errors add add it using set_js - that way before your form gets submitted - all error handling can be taken care @client level itself

 

2 - the ajax form submission and error handling is all the javascript functionality - u can deeply dug into the same and alter it as per your requirement (this is much tougher then the earlier one. Hence will recomend u go for the first solution)

 

Happy GCing :)

 

Dear GC Master
 
I am comfused sir.  I dont have any idea of what are you saying sir. Can you help me step-by-step sir? Im just a novice sir. Sorry
 
Sir, how about when I add/update/delete data, the success message will pop-up.  How can I do this sir? Something like alert box.
  Thanks in advance GC Master 

Edited by ineedhelp, 10 October 2013 - 03:15 PM.


#5 Json Sean

Json Sean

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 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.



#6 kadejo

kadejo

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 18 June 2020 - 12:10 AM

Thank you Json!!! this hack works great!

 

Some notes:

1 (first block): You may want to include the lines also inside the branch for callback_after_update if you need to support custom error messages in those kind of callbacks. Modify also db_insert (for insert/clone operations) and db_delete functions if you want to have the same custom message behaviour on their respective callbacks.

1 (second block): There is a trailing ',' behind $error_message and that mess the json decoding. It should be like this:

echo json_encode(array(
 'success' => $update_result['status'] ,
 'error_message' => $error_message
 ));

2-> Find correspondent js inside the theme used for displaying the form, i.e. assets/grocery_crud/themes/flexigrid/js/flexigrid-edit.js. Also you may want to do the same in -add.js file:

if(data.success)
{
    ...

    clearForm();
    form_success_message(data.success_message);
} 
else if (!data.success & data.error_message != null)
{
    form_error_message(data.error_message);
}
else
{
    alert( message_insert_error );
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users