Trying to make a module request form with name, email, attached images/files, and textarea for request info.
I have the form and can not seem to get the Ajax to to work. Right now I am just submitting and trying to send data back in a json format, but all I get is error/not-working.
I'm trying not to do this within Joomla and not go outside the Joomla 4.x frame work. Which I figure should be easy, but ends up being NOT....
Error:
Javascript on default template:
Service Provider: /modules/mod_omc_web_request/services/provider.php
Helper: /modules/mod_omc_web_request/src/Helper/WebRequestHelper.php
NOTE:
There may be some miss-type due to trying to hide actual "CompamyName" - Security.....
Thanks
I have the form and can not seem to get the Ajax to to work. Right now I am just submitting and trying to send data back in a json format, but all I get is error/not-working.
I'm trying not to do this within Joomla and not go outside the Joomla 4.x frame work. Which I figure should be easy, but ends up being NOT....
Error:
Code:
{"success":false,"message":"Method testAjax does not exist.","messages":null,"data":null}
Javascript on default template:
Code:
function testAjax(thisFormData){ document.getElementById('requestStatus').innerHTML = "Sending Data";jQuery(document).ready(function($) {var formData = new FormData($(thisFormData)[0]); jQuery.ajax({url: 'index.php?option=com_ajax&module=omc_web_request&method=test&format=json',type: 'POST',data: formData,async: false,cache: false,contentType: false,processData: false,success: function (returndata) { // was able to connect to serverresponseData=JSON.parse(returndata);document.getElementById('requestStatus').innerHTML = returndata;return false;},error: function (error) { // was not able to connect to serverdocument.getElementById('requestStatus').innerHTML = "<p>There was a problem submitting your request.</p>"; }}); });}
Service Provider: /modules/mod_omc_web_request/services/provider.php
Code:
<?php\defined('_JEXEC') or die;use Joomla\CMS\Extension\Service\Provider\Module as ModuleServiceProvider;use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory as ModuleDispatcherFactoryServiceProvider;use Joomla\CMS\Extension\Service\Provider\HelperFactory as HelperFactoryServiceProvider;use Joomla\DI\Container;use Joomla\DI\ServiceProviderInterface;return new class () implements ServiceProviderInterface { public function register(Container $container): void { //CompanyName\Module\ModuleName\ClientName//Acme\Module\SubscriptionStatus\Site//Acme\Module\LastBackupStatus\Administrator $container->registerServiceProvider(new ModuleDispatcherFactoryServiceProvider('\\Company\\Module\\OmcWebRequest')); $container->registerServiceProvider(new HelperFactoryServiceProvider('\\Company\\Module\\OmcWebRequest\\Site\\Helper')); $container->registerServiceProvider(new ModuleServiceProvider()); }};
Code:
<?phpnamespace Company\Module\OmcWebRequest\Site\Helper;\defined('_JEXEC') or die;use Joomla\CMS\Factory;use Joomla\Database\DatabaseInterface;use Joomla\CMS\Language\Text;class WebRequestHelper{ public static function getLoggedonUsername(string $default) { $user = Factory::getApplication()->getIdentity(); if ($user->id !== 0) // found a logged-on user { return $user; } else { return $default; } } public function testAjax(){$return['message'] = "This is a test and only a test ". __LINE__;$return['messages'] = "This is a test and only a test ". __LINE__;$return['data'] = "This is a test and only a test ". __LINE__;//return (string) $return;return $return;} public static function getAjax() { return "getAjax return"; } }
There may be some miss-type due to trying to hide actual "CompamyName" - Security.....
Thanks
Statistics: Posted by tpage68 — Mon Jul 22, 2024 7:49 pm