Joomla - using ajax in custom module - ajax

Requirments: I can't use components and ajax interface (joomla com).
My goal: Send POST data from default.php (mod_x) to helper.php (mod_x). Data is checked checkboxes - using ajax.
How to do this?
I know there has to be a method, to do this directly (can someone give me an example), by removing (I know its security risk, but there has to be a way to secure it by hacking joomla)
defined('_JEXEC') or die('Restricted access');
Is there some way to give a module task - just like you can do using component (controller)? I can't use component myself. How would this be done? Please be explicit.
Is there any other possible way? There has to be... I'm ready for some serious brain-storm. Let's get creative, guys.
P.S. To sum it up, I try to find some creative way to not use components, just module to do ajax call from default.php (ajax runs on checked checkbox/s)
I would prefer also an example in code. Thank you!

Fron Joomla 3.2 if you needed to make an AJAX request in Joomla! from a custom module or plugin, you can build the URL as below.
index.php?option=com_ajax&module=your_module_name&method=YourMethodName&format=json
Explanation of each parameter
1. index.php?option=com_ajax : ALL requests must be routed through com_ajax.
2. module=your_module_name: The first part of this is the type of extension you're using. This can either be 'module' or 'plugin'. The second part is the name of the extension. please take care you're not including the prefix 'mod_' or 'plg_', just the name.
3. method=YourMethodName: This is the method name that you are trying to call. If you're using this in a module then the method must be appended with 'Ajax'. So, the method represented here will be YourMethodNameAjax. If you're using this on a plugin, the method must be prepended with 'onAjax'. So, the method represented here will be onAjaxYourMethodName.
Check more at Joomla doc

Related

Change redirect after registration error in joomla

I wrote a plugin for joomla that adds custom fields to the user/register component. There are 3 different registration forms for different user groups.
The plugin acts on onUserAfterSave() and works fine, but there is one problem. When there is an error in the original user component, for example: "the username has already been taken" the form is redirected and neither onUserAfterSave() or onUserBeforeSave() is ever called.
I want to change that redirection, but without changing the core, but since neither plugin events are called, im not sure how to. Can you guys help me? Maybe I am missing something!
Is it possible to maybe override the save() function?
THANKS
I had same problem many times, so i can share a solution i use myself. If you don't want to edit Joomla core files, you can do the following:
Create your own template override of registration view.
Duplicate the components/com_users/controllers/registration.php file and lets say name it registration2.php
In your registration form override change hidden input's "task" value from registration.register to registration2.register
Feel free to override registration2.php classes how you like.
It's totally Joomla update proof, so you can update your joomla version witht worrying about errors.
I think you might need to do the checks that joomla is doing in your plugin and redirect in your plugin itself in the case that it wont pass. I see your predicament and I don't know a better way but I would pick a different event to run it on maybe even after page load and then on UI event in javascript.
The only clean way to extend the user registration/profile is to create a profile plugin like this one
https://github.com/joomla/joomla-cms/blob/master/plugins/user/profile/profile.php
You can extend com_users forms in backend and frontend.

Is it possible to extend Yii URL routes and rules through a Controller?

Is it possible to extend Yii URL routes and rules through a Controller on the fly, or by extending the CController class itself?
I am really stuck with this, have not tried anything.
How to do this in/with Yii?
First you should be aware of what URL rules are used for:
Parsing an incoming URL. The urlManager component resolves a URL to a route so that Yii can call the right action in a specific controller and module.
Creating URLs from calls to createUrl() in your code.
Considering (1) above it is obvious, that you can not add URL rules in your controller if you want to use these URLs in your application. It's much too late, as Yii already has gone through the process of resolving a request to a route. Even if you'd only wanted to create URLs it doesn't make much sense as your application will never understand them.
The correct way to bring more dynamics into your URL parsing/creation is to use a custom URL rule class. In there you can write any code you want to create and parse even the most complex URLs. The topic is described in the manual.

How to manage URLs in CodeIgniter so they can be updated in a single place

I believe Smarty templates has functionality built in that allows you to manage your site URLs from a config file so if something gets moved, you only have to update the URL in one place. Does this sort of functionality exist in CodeIgniter? If not, any pointers or examples on how/where to add it?
For example:
Instead of hard-coding the link it would be: Settings
But where would you want to set $links so that it was available everywhere? Or is it really best to just hard code them?
Take a look at the config class. It allows you to make custom config files.
It's not entirely made for URL's but you sure can use them.
The base url should be basically right at the start of /app/config/config.php, where app is the name of your codeigniter application folder. You access it through calls to the base_url() function.
Yes, it's called Routes, configuration located at config/routes.php. Documentation
If you ask about the rendered html of the links, then your best bet would be using site_url() in conjunction with constants, for example site_url(URL_SETTINGS);, there is no built in functionality for that, but I can say I don't think that is necessary as it would be used too rarely, but it would influence performance every single load.

Joomla 2.5 - Modify registration form and logic

Hello I'm new to Joomla and I want to change the way an account is created (in Joomla 2.5):
Change the registation form (remove one or two fields)
Change the registration logic: I want to add more stuff in the sent email (and a pdf attachment) and also i want to call some other functions (or make extra requests), analyse the result and then return the response to the client.
What ways are there?
Had an earlier answer for an earlier version that didn't apply, but found this tutorial to get myself up to speed. it lists all the files, etc. that you need to make changes to, but doesn't mention your email requirement. To do that, you'll likely have to look at function register($temp) in components\com_users\models\registration.php
You can change the settings from the component directory of the template in the PHP file.
you can if you install SEBLOD, it's a content constructor that can modify article form, user registration form and much more.
It will help you with almost everything you need, but to call other functions or make other requests you will nedd to digg a little more into Joomla registration.php

How to make AJAX call to myself from Joomla! module?

I wrote a module that is dependent on some third party device (load, parse & display). Sometimes it takes 5 seconds for it to respond so I tried to ajaxify this part.
My Joomla! module is ready as well as code with AJAX (mootools) but I can't figure out the URL to access my module php file "infused" by Joomla! (something like /index.php?option=com_content). I can hardcode and access it (/modules/mod_a/xyz.php) but I will run into "direct access not allowed" which is no trouble, but I don't have the Joomla! context which I pretty much miss.
All I found utilizes components which I would very much like to avoid.
Thanks for suggestions,
Regards,
Marek
You cannot access to your module by url. The only way to create very simple component with one model and one view for this purpose. Or you could add one task to one the components installed in your site.
I did write the simplest component I could (no MVC):
defined('_JEXEC') or die('Restricted access');
$task = JRequest::getWord('task');
if ($task == "getCurrentTemp") {
// return temperature
}
This can be printed (heredoc) to JS by JURI::current()."index.php?option=com_xzy&task=getCurrentTemp".
Not being able to access module sucks a little bit but I understand that from architectural point of view.

Resources