Jump to content


Error Messages


  • Please log in to reply
6 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 );
}


#7 manvikakkar98

manvikakkar98

    Newbie

  • Members
  • Pip
  • 4 posts
  • LocationMumbai, Maharashtra, India

Posted 21 September 2020 - 11:04 AM

Most of the clients who come to me never forget the evening they spent with me. Almost all of them desire to enjoy with a cute Independent Mumbai Escorts and their search ends at me. My name is Manvi Kakkar, who is a 22-year-old student. The clients have a lustful experience and they want to look me again and again. I am a five star rated Mumbai Call Girls, who knows numerous tricks to please the clients. I am much more beautiful than the photographs available in the gallery section of Mumbai Escorts Service. I am friendly, lovely girl, who can do anything to please the clients. Many of my clients recommend their friends to meet me at least once in the life. I take full care of my client and my magical performance leaves them stunned.

 

I am completely selfless and make every effort to please my clients. I am a real trooper to not leave even when the client gets a little late just as most would do. Clients feel my smoky body and the beautiful face. Off the shower, we go for a very sensual washing of each other’s body. So, whenever you plan to meet me i.e. a stunning beautiful Mumbai Call Girls, just give a call or drop a message. It is always advisable to book me in advance so that you’re not disappointed, when you need me the most. My profile is available at Mumbai Escorts Service and you can see my profile, containing my latest photographs and authentic body stats. Now, I am waiting for you. Come, if you’re looking to have something exclusive and special.  

 

Visit My Website:-

https://www.manvikakkar.com/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users