Overview
Callbacks play an important role in programming, particularly in series operations.
They are typically used to specify what should happen when an in-series operation takes place.
It allows you to work with non-blocking operations smoothly. However, JavaScript features have been introduced to simplify in-series codes and reduce the complexity associated with callbacks.
Callbacks are of two types Controller callbacks and Javascript callbacks.
- Controller Callbacks
- JavaScript Callbacks
Controller Callbacks
Controller callbacks are the functions used to manage and control the flow of the web application.
They are commonly used in the frameworks with MVC (Model-View-Controller) architecture.
It helps you structure your application’s behavior and handle various HTTP requests and actions efficiently.
Listing
-
Listing Page Before Load: This callback generally refers to a scenario where you want to execute a certain action or code just before a specific page is loaded or displayed. This callback is often used for tasks like pre-loading data and performing authentication checks.
The function can be declared in:
> application > libraries > general.php
> application > controllers > Controller_name.php
> application > models > Model_name.php
Syntax:
function FunctionName($render_arr)
{
// do your code
return $render_arr;
}
-
Listing Data Before Fetch: This callback function implies that you want to perform some processing before making any data request. Within your controller function, you have to write logic for fetching data. This might include a database query, an API request, or any other collection of data operations.
Syntax:
function FunctionName($data_config)
{
// do your code
return $data_config;
}
-
Listing Row After Process: This callback function refers to the situation where you want to do something important after dealing with data from the database row. Consider you have a list of items in a database, and when you work with one of those items, you want to perform extra actions afterward.
In After Process Callback, after you have done something with that item, you want to do more stuff, like sending notifications or updating related information.
Syntax:
function FunctionName($id, $row_data, $data_arr, $return_array)
{
// do your code
return $row_data;
}
-
Listing Data Before Load: This callback function means getting some information ready just before showing it on the page. It’s like preparing things before you display them to the user.
For Example:
In an Online Store, before showing a product’s details on a page, you might want to check if it’s in stock, fetch reviews, or ensure the user is logged in to checkout. All these checks and preparations happen before the page loads, and that’s all about this “Before Load Callback”.Syntax:
function FunctionName($data_recs, $grid_fields, $list_config)
{
// do your code
return $data_recs;
}
-
Left Search Before Load: This callback function, before showing the search results, Admin might want to do something special, like checking if there are any special requests or filters the user wants to apply to the search.
For example:
An e-commerce website you’re searching for a shoe could include filtering the results to only show sneakers, sorting them by price, and making sure the sizes you want are available. All these checks and preparations happen before the search results are displayed to you.Syntax:
function FunctionName($search_arr, $type, $alias_name, $term)
{
// do your code
return $search_arr;
}
Form
-
Form Data After Fetch: This callback function refers to the process where you do something with data from a form after retrieving it. After submitting the form, you want to do something special with that information, this could be things like saving it to a database, sending it an email, or processing it in some other way.
For example:
When someone fills out the Contact Us form on a website, this callback might involve taking the user’s message and sending it to the company owner’s email address. This is what happens with the form data after it’s been submitted.Syntax:
function FunctionName($data, $mode, $id)
{
// do your code
return $data;
}
-
Relational Module Data After Fetch: Once you find the information you need from another module, you want to do something special with it. This could be calculations, formatting, or any other kind of processing.
For example:
You have an online store with a database(“Relational Module”) containing product information. When a customer views a product page, this callback function might involve calculating the total price, checking if the product is in stock, and formatting the product details nicely for display all after fetching the basic product information from the database. It's about making sure the data is ready for the customer to see and interact with.Syntax:
function FunctionName($child_config, $relation_module, $data)
{
// do your code
return $child_config;
}
-
Add / Update / View Page Before Load: In this callback, before showing the user the page they want to add, update, or view an item, the controller wants to perform some important operations like checking if the user is allowed to make changes, getting the item details, or preparing the page in some other way.
Once the controller is finished doing the operations, the page is ready for the user to add, update, or view the page.
For Example:
Let's consider an online store
Add Page Before Load: Before you let someone add a product to your store, you want to check if they are an authorized seller or not and prepare a page to add a new product to the store. Update Page Before Load: Before someone can edit the product information like changing price, or attributes, you want to verify their permission to do that and and load the current details on the update page.
View Page Before Load: When a customer wants to view details of a product, you want to load those details and display them on the page.
function FunctionName($render_arr)
{
// do your code
return $render_arr;
}
-
Add / Update Form Page After Save: This callback refers to the process where you handle what happens after a user has added or updated the information in a form and clicked the “save” button.
After the user clicks the “Save” button on the form, you have to do some special operations with the data they have entered. This could be saving data to the database, showing a success message, or redirecting to another page.For Example:
Add Form Page After Save: Consider you’re adding a new product to an online store after you fill out all the product details in the form and click the “Save” button, this callback might show you a success message like “Product added successfully.” and maybe clearing the form so you can add new product details.
Update Form Page After Save: If you are updating an existing product’s details in the form and you click the “Save” the callback could show a message like “Product updated Successfully.” and take you back to the product listing page with the updated information.
Syntax:
function FunctionName($ret_arr)
{
// do your code
return $ret_arr;
}
Export
-
Export Data Before Fetch:This callback refers to a process where you get data ready for export, like creating a downloadable file, just before fetching it from sources like databases or API.
Before Fetch means it’s like preparing a document before printing it. This can include formatting the data, applying filters, or organizing it in a specific format for the export.
Export Data means this is the data you want to save as a file that the user can download. This can be the list of items in a spreadsheet, PDF report, CSV report, or any other downloadable content.For example:
Before fetching the product list from the database to create an export file, you might want it to format nicely, add a header, or remove some unnecessary information. This way a user downloads a list, it's well-organized and easy to use.Syntax:
function FunctionName($export_config)
{
// do your code
return $export_config;
}
-
Export Data Before Render:This callback function refers to a process where you get data ready for export, like creating a downloadable file, just before displaying it on a webpage.
Before Render means it’s like making sure everything looks perfect before you show it to someone. This task may include formatting data, applying filters, or organizing it in a specific format for display or download.
For example:
Before displaying the list of products on the web page or offering it as downloadable, you have to format it nicely.This callback is used to get the data ready for display or download in the best possible format.
Syntax:
function FunctionName($db_recs, $list_config, $misc_info)
{
// do your code
return $db_recs;
}
-
Print Record Before Render:This refers to the process where you prepare and format a specific record or data just before displaying it on the page for printing.
Before showing this information to printing, it’s like tidying up a document before you print it out, this includes formatting data, adding headers or footers, and making sure it looks nice for printing.
For example:
Before showing the invoice on the screen for printing, you might want to format it properly, and a company logo, and ensure it looks professional on the paper. This way, the user decides to print an invoice, and it comes out looking organized and presentable.Syntax:
function FunctionName($ret_arr)
{
// do your code
return $ret_arr;
}
-
Print Listing Before Fetch:In this callback, you prepare a list of items or data for printing before actually retrieving that list from a source like a database or API.
Just before getting this list from the database or API perform operations like organizing your papers before taking photocopies. These operations can be formatting the lists, sorting them, or applying filters to include certain criteria.
For example:
Before retrieving the list of products from the database for printing, you might want it to look neat. Make sure it is suitable for printing.Syntax:
function FunctionName($ret_arr)
{
// do your code
return $ret_arr;
}
-
Print Listing Before Fetch:This callback is the process where you prepare a list of items or data for printing just before displaying it on a web page for the user to print.
Just before showing this list of things on the web page for printing, the operations are performed, it’s like making sure everything looks nice and organized before you hand it to someone to print. This task could involve formatting the list, adding titles or page numbers, or making sure it fits well on paper.
For example:
Before showing the list of orders on the screen for printing, you might want to format it nicely, add headers and footers with details like the date and company logo, and ensure it looks professional when printed. This way, when users decide to print the list of orders, it comes out looking well-organized and ready to use.Syntax:
function FunctionName($print_config)
{
// do your code
return $print_config;
}
Others
-
Expand Grid Listing Before Load:This function refers to the process where you prepare a grid or a table of data to be displayed on a web page, and you want to make sure it's ready for viewing with additional details or expanded content.
Before showing this list of items in the grid, operations are performed for loading more detailed information about each item, applying filters, or arranging the items in a specific order.
For example:
Before displaying a list of products in a grid, you might want to fetch additional information about each product, such as reviews, ratings, or availability, and then arrange them nicely in the grid. This way, when users view the product list, they see not just basic information but also more details about each product.Syntax:
function FunctionName($print_config)
{
// do your code
return $print_config;
}
-
Expand Detail View Before Load:This callback refers to the process where you prepare a detailed view of something like a product, an article, or a user profile just before it's shown to the user.
Before showing the user this detailed information, some operations are performed. These could be loading more data related to that item, checking permissions, or formatting the information for a better display.
Detail view is the part of the web page where you show all the basic details about the item, like the specifications of a product, the content of an article, or the profile information of a user.For example:
Before showing a detailed view of a product when a user clicks on it, you might want to load more information, such as customer reviews, related products, or even the product's availability in nearby stores. This way, when the user looks at the product in detail, they get a richer and more informative view.Syntax:
function FunctionName($print_config)
{
// do your code
return $print_config;
}
-
Top Detail View Before Load:Before showing this detailed information, operations are performed like preparing a backstage area before a big show. This task could involve loading more data, checking permissions, or organizing the information for a better presentation.
The top detail view is the part of the web page where you display all the important details about the item, like the specifications of a product, the content of an article, or the profile information of a user.
For example:
Before showing all the interesting details about a product when a user clicks on it, you might want to load extra information, such as customer reviews, related products, or stock availability. This way, when the user dives into the product details, they get a richer and more informative view.Syntax:
function FunctionName($print_config)
{
// do your code
return $print_config;
}
JavaScript Callbacks
Javascript callbacks are widely used in front-end and back-end development. They allow you to specify a function to be executed when another function finishes its execution.
Listing
-
Listing Grid Before Init:This callback function refers to a process where you perform some actions or setup before initializing or creating a grid or table that displays a list of items.
Before you actually create or set up this grid, you have to do some operations. It's like preparing the stage before a performance. This task could involve fetching data, configuring how the grid looks, or applying certain settings.
For example:
Before you display a grid of products on a webpage, you might want to fetch product data from a database, apply filters to show only available items or set up the grid to display them in a particular order. This way, when users view the product list, it's ready with the right data and appearance.function FunctionName(el_grid_settings, js_col_model_json, js_col_name_json)
{
// do your code
}
-
Listing Data After Load:This callback function refers to the process where you perform some actions or manipulation on a set of data after it has been loaded or fetched.
After you've retrieved this data, you have to perform some operations on it. It's like making adjustments or additions to a meal after it's been cooked and served. This task could involve sorting the data, filtering it, formatting it, or adding additional information.
For example:
After fetching this list of user profiles from a database, you might want to rearrange them in alphabetical order, filter out profiles that don't meet certain criteria, or calculate statistics like the average age of the users. This way, the data is ready for display or further use with the desired modifications.Syntax:
function FunctionName(data)
{
// do your code
}
-
Records Delete - Before Submit:This callback function refers to a process where you take some actions or make decisions just before you submit a request to delete one or more records (data entries) from a system or database.
Just before you click the button to confirm the deletion, you perform some special operations. It's like double-checking if you really want to delete those items or preparing the delete operation in some way.
This callback could involve various tasks:
- Confirmation: You might want to ask the user for confirmation to make sure they really intend to delete the records.
- Data Validation: You could check if the records meet certain criteria for deletion, like ensuring they are not linked to other data.
- Logging: You might log the deletion for audit purposes, so you have a record of what was removed and when.
So, "Records Delete - Before Submit" is all about taking precautionary or preparatory actions just before you confirm the deletion of records from a system or database. It's like making sure you really want to delete something and getting things ready for that delete operation.Syntax:
function FunctionName(postdata)
{
// do your code
return [ true/false, "message" ];
}
-
Records Delete - After Submit:This callback function refers to a process where specific actions are taken after you have submitted a request to delete one or more records (data entries) from a system or database.
After you've confirmed and submitted the request to delete these records, you perform some operations. It's like taking additional steps after you've pressed the "delete" button to make sure the deletion process is completed correctly.
This callback could involve various tasks:
- Confirmation: You might display a message to the user confirming that the records have been successfully deleted.
- Cleanup: You could perform additional actions to clean up any associated data or resources that were connected to the deleted records.
- Logging: You might log the deletion process, recording which records were deleted and when.
So, "Records Delete - After Submit" is all about handling the aftermath of deleting records from a system or database. It's like making sure everything is tidied up and the user is informed once the deletion is complete.Syntax:
function FunctionName(response, postdata)
{
// do your code
}
-
In-line Edit - Before Submit:This callback refers to a process where you perform actions or checks just before you submit changes made during an in-line edit operation.
Imagine you're on a web page, and you click on some text or data to edit it directly within the page itself. This is called in-line editing. It's like correcting a typo in a document without opening a separate editor.
Just before you save the changes you made during in-line editing, you have to do some important operations. It's like reviewing your changes or adding extra details before you finalize and save them.This callback could involve various tasks:
- Validation: Checking if the edited content meets certain criteria, like ensuring it's not empty or that it adheres to a specific format. - Confirmation: Asking the user to confirm if they really want to save the changes. - Data Adjustment: Modifying the edited content in some way, like formatting dates or cleaning up user input. So, "In-line Edit - Before Submit" is about preparing the changes made during in-line editing for submission. It's like making sure everything is in order before you save the edited content.Syntax:
function FunctionName(rowid, cellName, cellValue, iRow, iCol)
{
// do your code
}
-
In-line Edit - After Submit:This callback function refers to a process in web development where specific actions are taken after you've submitted changes made during an in-line edit operation.
Once you've made your edits and clicked a "save" or "submit" button to confirm the changes, there are things you want to do afterward.
This callback could involve various tasks:
- Confirmation: Displaying a message to the user confirming that the changes have been successfully saved.
- Updating Data: Making sure the changes are reflected in the underlying data or database.
- Refreshing Display: Refreshing the part of the page where the edited content is shown to reflect the latest changes.
So, "In-line Edit - After Submit" is all about handling what happens after you've submitted your edits during in-line editing. It's like wrapping up the editing process and making sure everything is updated and confirmed.
Syntax:
function FunctionName(response, rowid, cellname, value, iRow, iCol)
{
// do your code
return true/false;
}
-
Status Change - Before Submit:This callback function refers to a process where you take certain actions or perform checks just before you submit a request to change the status of something.
Just before you confirm and submit the request to change this status, you have to do some important operations. It's like making sure everything is in order before you officially make the change.
This callback could involve various tasks:
- Validation: Checking if the change you're trying to make is allowed or valid. For example, ensuring you can't mark an already read email as "unread."
- Confirmation: Asking the user to confirm that they indeed want to make this status change.
- Data Adjustment: Modifying the status change request in some way, like adding additional information or altering the description of the change.
So, "Status Change - Before Submit" is all about preparing and confirming the status change you want to make before you officially submit it. It's like double-checking to ensure everything is set up correctly for the change.Syntax:
function FunctionName(postdata)
{
// do your code
}
-
Status Change - After Submit:This callback function refers to a process where specific actions are taken after you have submitted a request to change the status of something.
Once you've confirmed and submitted the request to make this status change, there are things you want to do afterward. It's similar to completing tasks after sending an important email.
This callback could involve various tasks:
- Confirmation: Displaying a message to the user confirming that the status change has been successfully applied.
- Updating Data: Ensuring that the status change is reflected in the underlying data or database.
- Triggering Actions: Initiating additional actions or processes that depend on the new status. For instance, sending a confirmation email when an order status changes to "shipped."
So, "Status Change - After Submit" is all about handling what happens after you've successfully submitted a request to change the status of something. It's like wrapping up the status change process and making sure everything is updated and confirmed.
Syntax:
function FunctionName(response)
{
// do your code
}
Form
-
Form Javascript After Load:This callback function refers to a process where you perform certain actions or tasks after a web form has been loaded or displayed.
Think of a form as a section of a web page where you can enter information, like a login form, a contact form, or a survey.
After the web form has appeared on the page, you have to do some important operations. It's like checking your mailbox after the mail has been delivered.
This special task could involve various actions:
- Data Initialization: Setting up default values or pre-filling some fields in the form.
- Validation Setup: Configuring rules to check if the data entered in the form is correct or complete.
- Event Handling: Adding functions or behaviors to certain elements in the form, like buttons or input fields.
For example:
After the registration form is displayed on the page, you might want to initialize some fields with the user's previous information (if they've partially filled it out before), set up rules to ensure the password meets security criteria and attach an event handler to the "Submit" button to process the form data when it's submitted.
Syntax:
function FunctionName(response)
{
// do your code
}
-
Form Validations Error Callback:This is a process where you handle what happens when errors occur during the validation of a web form.
Validation is like checking the information you've entered in the form to make sure it's correct and complete. For example, ensuring that an email address has the "@" symbol or that a password is long enough.
An error callback is a special function or code that gets executed when there are problems with the information you entered in the form. It's like a warning sign that something needs to be fixed.
So, "Form Validations Error Callback" is all about what happens when you fill out a form, but there are mistakes or missing information. It's like the form telling you, "You made some errors." This callback helps you handle and display those error messages to the user so they know what went wrong and how to correct it.
Syntax:
function FunctionName(response)
{
// do your code
}
-
Relation Module - Before Add:This callback function refers to a process where you perform specific actions or checks just before adding a new relationship or connection between elements in a system.
Think of a Relation Module as a system or component in your web application that manages how different elements or objects are related to each other. For example, it might manage how users are connected to groups or how products are associated with categories.
Just before you confirm and add a new relationship between elements, you have to do some important operations. It's like double-checking if the relationship is valid or preparing additional details before it's officially created.
This callback could involve various tasks:
- Validation: Checking if the relationship you're trying to create is allowed or makes sense. For instance, ensuring you can't add a user to a group that doesn't exist.
- Confirmation: Asking the user to confirm if they really want to create this relationship.
- Data Adjustment: Modifying the relationship request in some way, like adding additional information or altering the description of the relationship.
So, "Relation Module - Before Add" is all about preparing and confirming a new relationship between elements just before you officially create it. It's like making sure everything is set up correctly for the relationship to work.
Syntax:
function FunctionName(response)
{
// do your code
}
-
Relation Module - After Add:This callback function refers to a process where you perform specific actions or tasks after you have successfully added a new relationship or connection between elements in a system.
Imagine a part of your web application that manages how different things are connected to each other. For instance, it might handle how users join groups or how products get linked to categories.
Once you've confirmed and added a new relationship between elements, there are things you want to do afterward. It's like taking care of additional steps after you've successfully connected two things.
So, "Relation Module - After Add" is all about handling what happens after you've successfully added a new connection or relationship between elements. It's like wrapping up the process and making sure everything is updated and confirmed.
Syntax:
function FunctionName(response)
{
// do your code
}
-
Relation Module - Before Save:This callback function refers to a process where you perform specific actions or checks just before you save changes or updates to a relationship or connection between elements in a system.
Just before you confirm and save changes to an existing relationship, you have to do some essential operations. It's like double-checking if the changes are valid or preparing additional details before they are officially saved.
So, "Relation Module - Before Save" is all about preparing and confirming changes to a relationship between elements just before you officially save them. It's like making sure everything is set up correctly for the changes to be applied.
Syntax:
function FunctionName(response)
{
// do your code
}
-
Relation Module - After Save:In this callback function, once you have confirmed and saved to an existing relation, there are things you want to do afterward. It’s like taking care of additional steps after you have successfully updated the connection.
This callback could involve various tasks:
-Confirmation: Displaying a message to the user confirming that the changes are updated successfully.
-Updating Data: Ensuring that the changes are reflected in the database
-Triggering Actions: Initiating additional actions that depend on updated relations.
So, “Relation Module - After Save” is all about handling what happens after you successfully save changes or updates between the elements.Syntax:
function FunctionName(response)
{
// do your code
}
-
Relation Module - Before Delete:This callback function refers to a process where you perform specific actions or checks just before you confirm and execute the deletion of a relational module or connection in the system.
Just before you confirm and delete an existing relation, you have to do some important operation, it’s like double checking if the deletion is valid or not.
This callback could involve various tasks:
- Validation: Checking if the relationship you're trying to create is allowed or makes sense. For instance, ensuring you can't add a user to a group that doesn't exist.
- Confirmation: Asking the user to confirm if they really want to create this relationship.
- Data Adjustment: Modifying the relationship request in some way, like adding additional information or altering the description of the relationship.
So, “Relation Module - Before Delete” is all about preparing and confirming the deletion of the relation between elements just before you officially delete it.Syntax:
function FunctionName(response)
{
// do your code
}
-
Relation Module - After Delete:This callback function refers to a process where you perform specific actions or tasks after you have successfully deleted a relation or elements in a system.
Once you've confirmed and executed the deletion of an existing relationship, there are things you want to do afterward. It's like taking care of additional steps after you've successfully removed the connection.
This callback could involve various tasks:
-Confirmation: Displaying a message to the user confirming that the changes are updated successfully.
-Updating Data: Ensuring that the changes are reflected in the database
-Triggering Actions: Initiating additional actions that depend on updated relations.
So, “Relation Module - After Delete” is all about handling what happens after you have successfully deleted relations between elements.Syntax:
function FunctionName(response)
{
// do your code
}