Skip to Content

Welcome!

This community is for professionals and enthusiasts of our products and services.
Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

This question has been flagged
As a moderator, you can either validate or reject this answer.
Accept Reject
54 Views

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', '');

Avatar
Discard

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Related Posts Replies Views Activity
0
Dec 24
47
0
Jan 24
18
1
Mar 24
75
1
Nov 23
57
0
Jan 24
62