1. Right click to create a new file called "helper.php" inside modules
2. Paste below code inside the new file (You can use AI like chatgpt or deepseek to check whether it is still valid or not)
<?php
/**
* @copyright Copyright (c) 2021 Shopping cart feed activity pop up. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
// no direct access
defined('_JEXEC') or die;
/**
* Shopping cart feed activity pop up - Shopping cart feed activity pop up Helper Class.
*
* @package Joomla.Site
* @subpakage Shoppingcartfeedactivitypopup.Shoppingcartfeedactivitypopup
*/
class modEbwhatsappchatHelper
{
<<<Start you coding here>>>
}
3. How build the helper function?
static function sendEmailFromLivechatAjax(){
}
Desc:
-the class name should be<< mod+ your module name + Helper >>
-create a function name and add 'Ajax' in the last one
4. How to call it on the other file?
You can direct use ajax to call it like below
jQuery.ajax({
type: 'POST',
url: '/index.php?option=com_ajax&module=ebwhatsappchat&method=sendEmailFromLivechat&format=json',
data: {
name: name,
contact: phoneNumber,
email: email,
message: message,
website: currentUrl,
},
success: function (response) {
console.log("AJAX success response: ", response);
try {
var jsonResponse = JSON.parse(response);
//alert('PHP function executed: ' + jsonResponse.message);
} catch (e) {
console.error("Error parsing JSON response:", e);
alert("Unexpected response: " + response);
}
},
error: function (xhr, status, error) {
console.error("AJAX error: ", error);
console.error("Status: ", status);
console.error("XHR object: ", xhr);
alert('Error executing function.');
}
});
Desc: Key point is the ajax url
/index.php?option=com_ajax&module=ebwhatsappchat&method=sendEmailFromLivechat&format=json
Module = your module name without mod_ (mod_ebwhatsappchat)
method = your method name without Ajax (sendEmailFromLivechatAjax)
data: { } = this data can changed based on scenario
Summary:
1. Create helper.php file in your module
2. Build function in the helper.php
3. Call the function via ajax in the other file
TIPS: Below code make you able get the data{} in the ajax (example only):
// Get the application object
$app = JFactory::getApplication();
// Get the input data
$input = $app->input;
// Retrieve POST data
$name = $input->post->getString('name', '');
$contact = $input->post->getString('contact', '');
$email = $input->post->getString('email', '');
$livechatMessage = $input->post->getString('message', '');
$website = $input->post->getString('website', '');