URL from button in ACP

Developer Networks
Developer Networks
@developer-networks
11 months ago
566 posts
 
function myModule_init(){
    // Adds the Back Office Login tab
    jrCore_register_module_feature('jrCore','admin_tab','myModule','backoffice','Back Office Login');
    return true;
}

I have a button added to my module in the config tabs to the module but i want to tell Jamroom to go to another URL entirely. How do i properly tell Jamroom that when clicking on this button it goes to the other website?
updated by @developer-networks: 04/04/24 09:29:41PM
Developer Networks
Developer Networks
@developer-networks
11 months ago
566 posts
I tried to create a view so php could redirect to the url like this but it returns a 500 error. What am I doing wrong?
<?php

// Retrieve the value of the 'store_url' setting
$store_url = jrCore_get_setting('myModule', 'store_url');

// Check if the URL is valid before using it
if (filter_var($store_url, FILTER_VALIDATE_URL) === false) {
    // Handle invalid URL (e.g., display an error message)
    echo 'Invalid Back Office URL';
    exit();
}

// Redirect to the BackOffice URL
header('Location: ' . $store_url);
exit();
michael
@michael
11 months ago
7,715 posts
do that in your function.

URL_Goes_Here, that function gets called, inside that function redirect to where ever you want to redirect to.
Developer Networks
Developer Networks
@developer-networks
11 months ago
566 posts
I created a function in the module init and I then put the name of the function in that place and it just tried to go to a page view of what the function was called.

So I put the function back on the view page backoffice.php and it has a 500 error.

Can you please provide an example of what you ment?

Where 'store_url' holds the name I saved in the config file to the datastore for the module with the URL.


Heres the code in the config file where i input the url
    $_tmp = array(
        'name'     => 'store_url',
        'default'  => '',
        'type'     => 'text',
        'validate' => 'url',
        'label'    => 'Store URL',
        'help'     => 'Enter the Store URL',
        'order'    => 1
    );
    jrCore_register_setting('myModule', $_tmp);


Thanks
updated by @developer-networks: 01/01/24 06:51:52PM
Developer Networks
Developer Networks
@developer-networks
11 months ago
566 posts
I get it working with this on the backoffice page view but i want to use the store_url from the module.
<?php
// Redirect to another website
$redirect_url = 'https://store.mysite.com/login?back=my-account';
header('Location: ' . $redirect_url);
exit(); // Make sure to exit after sending the header to ensure the script stops executing

Developer Networks
Developer Networks
@developer-networks
11 months ago
566 posts
I also tried...

<?php
// Redirect to another website
// $redirect_url = 'https://store.mysite.com/login?back=my-account';

$redirect_url = $_conf['myModule_store_url'] ;


header('Location: ' . $redirect_url);
exit(); // Make sure to exit after sending the header to ensure the script stops executing


and i also tried... 

$redirect_url = jrCore_get_setting('myModule', 'store_url');


but im not doing it right..
updated by @developer-networks: 01/01/24 08:33:46PM
Developer Networks
Developer Networks
@developer-networks
11 months ago
566 posts
<?php
function myModule_redirect() {
    // Retrieve the value of the 'store_url' setting
    $myModule_store_url = jrCore_get_setting('myModule', 'store_url');

    // Check if the URL is valid before using it
    if (filter_var($myModule_store_url, FILTER_VALIDATE_URL) === false) {
        // Handle invalid URL (e.g., display an error message)
        echo 'Invalid Store URL';
        exit();
    }

    // Redirect to the store URL
    header('Location: ' . $myModule_store_url);
    exit();
}

updated by @developer-networks: 01/01/24 08:41:53PM
Developer Networks
Developer Networks
@developer-networks
11 months ago
566 posts
Is there videos on how to get the data from the datastore in jamroom? I tried the jrCore_get_setting function i found from reading your code to pull it... I looked for documentation or videos but there doesn't seem to be anything available but this one line

 $_temp = jrCore_db_get_item('xxFoo', $id);

do i use get item instead of get setting?



updated by @developer-networks: 01/01/24 10:14:16PM
Developer Networks
Developer Networks
@developer-networks
11 months ago
566 posts
I thought you had a function for it and could help provide clarity where the docs are lackin'
michael
@michael
11 months ago
7,715 posts
If you want to get items from within a template use {jrCore_list .....}

Docs: {jrCore_list}
https://www.jamroom.net/the-jamroom-network/documentation/module-developer-guide/89/jrcore-list


If its from the php side then use jrCore_db_search_items()

Docs: Datastores
https://www.jamroom.net/the-jamroom-network/documentation/module-developer-guide/1023/datastores

Docs: PHP Functions
https://www.jamroom.net/the-jamroom-network/documentation/module-developer-guide/3983/php-functions
brian
@brian
11 months ago
10,148 posts
You can't have a URL on an admin tab, since it does not make sense from a UI perspective. A "tab" flips between sections in the current page. What you want to do instead is register it as a TOOL - then you can have a URL that goes offsite if you want - i.e. from the Developer tools module:

jrCore_register_module_feature('jrCore', 'tool_view', 'jrDeveloper', jrCore_get_base_url() . "/modules/jrDeveloper/adminer.php", array('Database Admin', 'Browse your Database Tables - <b>carefully!</b>'));



--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Developer Networks
Developer Networks
@developer-networks
11 months ago
566 posts
Thank you both those answers are super helpful.

I couldn't make it back to look at the code today but I will hopefully soon.

We are trying to pass the configuration variable from the datastore in our module called "store_url" as a button in the modules ACP windows for the admin because we are bridging Jamroom to another API

So the URL they input in the config file of the module will simply take admins to that sub domain with the API bridged and logged in. Thanks
updated by @developer-networks: 01/04/24 07:18:10PM

Tags