1

I have a module, and a number of different fields for authentication with an API.

I want to perform the API authentication when the Save button is clicked, and return a success or fail message depending on the authentication?

How can I achieve this in Joomla?

  • This feels a bit Broad. Did you begin to code this up yet? Volunteers in this community are not expected to write whole scripts from scratch or provide tutorials. Please show us how far you've written your task. – mickmackusa Aug 14 '18 at 6:35
1

Create a plugin with onExtensionBeforeSave and/or onExtensionAfterSave event.

public function onExtensionBeforeSave($context, $item, $isNew)
{
    // Check that we are editing our module.
    if ($context !== 'com_modules.module' || $item->module !== 'mod_example')
    {
        return true;
    }

    // Do stuff here.
    $params = new JRegistry($item->params);

    // Our stuff fails, don't save the module.
    if (!$this->doStuff($params))
    {
        return false;
    }

    return true;
}

Alternative way, which may or may not be suitable in your case, is to create a form validation rule in your module. This would not require a plugin. See documentation https://docs.joomla.org/Server-side_form_validation.

  • Hi, this is what I found to be the solution. However, this fires on every Save. I only want to capture the save event when my module is saved. Can this be achieved? Also, I need to access the parameters of the module in this function? How can I do that? Thanks! – Sergiu Tripon Aug 14 '18 at 10:19
  • You need to check that you're in the right context and that you're editing your module. This data is available through arguments. Params are available as JSON string. You can decode it or turn it into Registry object. Updated the answer to reflect this. Also, there is an alternative way of doing this, without the need for a plugin, by creating a form validation rule in your module. – Sharky Aug 14 '18 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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