1

I followed this guide step by step and I've just created a plugin that should elaborate AJAX calls received from a form in the front-end, so that the data sent by every user will be structured and manipulated on the back-end before sending an email to everyone of them. The forn is written in HTML, CSS and pure Javascript, meaning that it's been constructed out of the Joomla framework. My Joomla version is the 3.10.11 .

So, I created 3 files:

  1. formplugin.php
  2. formplugin.xml
  3. index.html

Eventually I've installed the plugin and everything seemed to be alright.

First file content is the following one:

<?php
    defined('_JEXEC') or die;


    use Joomla\CMS\Factory;
    use Joomla\CMS\Plugin\CMSPlugin;
    jimport('joomla.plugin.plugin');


    class plgAjaxFormplugin extends JPlugin {


        protected $app;
        protected $autoloadLanguage = true;


        public function onAjaxFormplugin() {


            var_dump("prova");


            return "prova";
        }
    }
?>

"formplugin.xml" is constructed like this:

<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" group="ajax" method="upgrade">
   <name>formplugin</name>
   <author>Autore</author>
   <creationDate>Apr 2023</creationDate>
   <license>MIT</license>
   <authorEmail>[email protected]</authorEmail>
   <authorUrl>www.sitoweb.it</authorUrl>
   <version>0.01</version>
   <description>FORMPLUGIN_XML_DESCRIPTION</description>
   <files>
      <filename plugin="formplugin">formplugin.php</filename>
      <filename>index.html</filename>
   </files>
</extension>

"index.html" contains the classic single row:

<!DOCTYPE html><html></html>

On the client side I am temporarily trying to send HTTP GET requests with Postman, with this URL:

http://localhost/joomla_3-10/index.php?option=com_ajax&plugin=formplugin&format=raw

Every request seem to be successful, I get the 200 code. The problem is that no response is given, anyhow. It's like the "onAjaxFormplugin" function is not even called.

What could the origin of this problem be?

5
  • You're aware that Postman isn't a browser and therefore can't execute JavaScript? I'm not familiar with how Joomla plugins work specifically, and I don't know what your index.php script does, but all Postman will do there is make a request to index.php, and see whatever raw response is given back. I'm guessing that if you loaded index.php into your browser, it would then run some JS which would then make the expected AJAX reuqest using JS code?
    – ADyson
    Apr 14 at 10:18
  • @ADyson index.php just loads the framework and the Joomla application. The "com_ajax" component is the one that processes the AJAX calls. In the Joomla docs is specified that to call a component one just have to send its request to index.php with the param "option=com_ajax". When you use this param you get in touch with the "Ajax interface", the guide of which I linked in the first row of my post. I tried to make some real AJAX requests too, from the browser, but I obtain the same result: a 200 response with no content. No matter what I write in the onAjaxFormplugin function
    – smarmolena
    Apr 14 at 10:28
  • "I'm not familiar with how Joomla plugins work" ...this is why I 100% recommend that you ask your Joomla questions on Joomla. Apr 15 at 6:31
  • @smarmolena I prefer to have all Joomla questions on Joomla Stack Exchange. If you agree to migrating this page to that community, please join JSE and leave me a comment under this one stating that you permit the migration. Apr 18 at 9:50
  • @mickmackusa yes, sure, you can. I've just joined JSE
    – smarmolena
    Apr 19 at 13:01

1 Answer 1

1

I eventually solved the problem, it was simply dued to the fact that I installed/uninstalled the plugin too many times and forgot to enable it after that. Now that I enabled the plugin everything works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.