Add php code to onload of a fabrik list

MR

New Member
hello,
i have a list of products and i want to add php code to it, the php code will be executed onload of the list, so that if someone refreshes the list from the browser while his connection session is over he will be redirected to login page.
How can i do that ? i found php code for it but can't add it on load of the list.

thnx a lot.
 
I hate when that happens.:p
IMO this should be a standard option for both Fabrik Lists and Forms.
I.e. An option in the List/Form configuration to always re-check for an expired user session before rendering - like 'Redirect url if not logged-in:".

Anyway...
You want to use the list 'php_events' plugin. In the onFiltersGot put some code that will check the user session and redirect to another page (the login form) if the user is not logged in
 
I hate when that happens.:p
IMO this should be a standard option for both Fabrik Lists and Forms.
I.e. An option in the List/Form configuration to always re-check for an expired user session before rendering - like 'Redirect url if not logged-in:".

Anyway...
You want to use the list 'php_events' plugin. In the onFiltersGot put some code that will check the user session and redirect to another page (the login form) if the user is not logged in

Does this option exist or not ?
"An option in the List/Form configuration to always re-check for an expired user session before rendering - like 'Redirect url if not logged-in:".

Or should I go through the "the list 'php_events' plugin" ? and where will i find it do u have the download link of this plugin ?
thnx a lot
 
No, that option isn't part of Fabrik (as far as I know). I'm just suggesting it should be!
The form php_events plugin is a standard Fabrik plugin and should already be installed. (If not you will have to update from github).

Just edit the Fabrik list configuration on the admin backend, select 'Plugins', +Add - and you will see it in the '--do--' dropdown list.

This code should do it...
PHP:
$user = JFactory::getUser();
if ($user->guest) {
    $app = JFactory::getApplication();
    $message = "You must be logged in to view this content";
    $url = JRoute::_('index.php?option=com_users&view=login');
    $app->redirect($url, $message);
}
 
Last edited:
That's exactly what does happen on my site without adding any code:

1. Login to front end and display list
2. Login to back end and force user log off
3. Refresh list on front end
4. It redirects to the login page
5. After entering login credentials it goes back to the list

Have you set View List to Registered in the list's access settings?
 
No, that option isn't part of Fabrik (as far as I know). I'm just suggesting it should be!
The form php_events plugin is a standard Fabrik plugin and should already be installed. (If not you will have to update from github).

Just edit the Fabrik list configuration on the admin backend, select 'Plugins', +Add - and you will see it in the '--do--' dropdown list.

This code should do it...
PHP:
$user = JFactory::getUser();
if ($user->guest) {
    $app = JFactory::getApplication();
    $message = "You must be logged in to view this content";
    $url = JRoute::_('index.php?option=com_users&view=login');
    $app->redirect($url, $message);
}

OK thank you so much i'll try it and get back to you i have any questions.
 
That's exactly what does happen on my site without adding any code:

1. Login to front end and display list
2. Login to back end and force user log off
3. Refresh list on front end
4. It redirects to the login page
5. After entering login credentials it goes back to the list

Have you set View List to Registered in the list's access settings?

Yes i did set View List to Registered but it just shows a message "u r not allowed to ..." but doesn't go to login, but it does go when i click on the menu item but i refresh the page using the browser it shows the message and stays in it no redirection.
 
Have you set the page itself to Registered in your menu item settings? Joomla should take care of your login redirections, you don't need to do it in Fabrik.
 
Have you set the page itself to Registered in your menu item settings? Joomla should take care of your login redirections, you don't need to do it in Fabrik.

Set the page to registered ? can u explain as i have a menu item that takes the user lo login page, and after login to the list ? which page should set to registered ? as i need the menu that takes to the login page to appear to everyone.
 
Set the page to registered ? can u explain as i have a menu item that takes the user lo login page, and after login to the list ? which page should set to registered ? as i need the menu that takes to the login page to appear to everyone.
The Fabrik page. Presumably you have a menu item of "Fabrik ? List" type. Set that to registered.
 
If you create a Fabrik list menu item and make it the default page in the menu manager, set its access to registered, Joomla will automatically present users with a login page when they first access the site and subsequently when pages are refreshed after sessions expire. You don't need redirects, Joomla handles it.
 
Good points Nick. I forget how the latest and greatest Joomla works sometimes because I use a redirect script.

And that's all well and good, without any second thought - so long as you want a 'members only' website. If you need to provide 'the public' with access to other articles and pages, you would need to make sure those 'public' pages are included on the menu on the same page as the login form. Or create 2 separate menus - one for users/members and one for guests - especially if you don't want pages intended for 'guests only' shown in a menu used by members.

For developers and designers new to Joomla, the "Guest' and 'Public' difference in Access levels might be confusing. Just remember that anything with access set to 'Guest' is not shown to anyone but Guests (not logged in) . But pages set to 'Public' show to both (logged-in) members and guests. And adding a 'Nobody' user type/access level (with all access levels unchecked) seems to be a standard way of preventing something from being shown to anybody. (The last I checked that is not included in the standard Joomla Access levels.)
 
If you create a Fabrik list menu item and make it the default page in the menu manager, set its access to registered, Joomla will automatically present users with a login page when they first access the site and subsequently when pages are refreshed after sessions expire. You don't need redirects, Joomla handles it.
yes but the page that contains the list isn't my default page, i have another home page
 
It doesn't make any difference, I can't think of an authentication scenario with any combination of public and private content that cannot be handled by Joomla's automatic redirection. There are many ways of achieving what you need, depending on whether you want users to login when they arrive at the site before accessing any content at all, or if some content is public and can be accessed by visitors. You just need to design the user experiences you want in a series of scenarios to make sure that every one is being achieved in your implementation.

A couple of examples:

If you want to create a private site, then make all the content on your home page except for a login module Registered. Set the login module to Guest. As soon as the user is authenticated the rest of the content will be rendered and the login module will disappear. Then create menu items to Fabrik lists and other private content and set them to Registered. Users will be able to access them because they have already logged in but if their session times out they will be forced by Joomla to login again. Set other menu items to Public. It is fundamental to the design of a Joomla website that all of your pages have related menu items, even if they are in a hidden menu. That's how they can be indexed, featured in sitemaps, breadcrumbs and have SEO friendly URLs assigned to them.

If you have a combination of public and private content then set the home page and any other public content to Public and leave the login module visible for users to use whenever they want to (like it is on the community and resource areas of joomla.org). Have a login menu item too if you want to, but don't make that the way to access the Fabrik list, do that using a separate menu item which has permissions set to Registered.
 
Last edited:
Thank you, a very lucid explanation. And is exactly why we don't bother providing this as a built in option, as it's a standard J! feature.

-- hugh
 
It doesn't make any difference, I can't think of an authentication scenario with any combination of public and private content that cannot be handled by Joomla's automatic redirection. There are many ways of achieving what you need, depending on whether you want users to login when they arrive at the site before accessing any content at all, or if some content is public and can be accessed by visitors. You just need to design the user experiences you want in a series of scenarios to make sure that every one is being achieved in your implementation.

A couple of examples:

If you want to create a private site, then make all the content on your home page except for a login module Registered. Set the login module to Guest. As soon as the user is authenticated the rest of the content will be rendered and the login module will disappear. Then create menu items to Fabrik lists and other private content and set them to Registered. Users will be able to access them because they have already logged in but if their session times out they will be forced by Joomla to login again. Set other menu items to Public. It is fundamental to the design of a Joomla website that all of your pages have related menu items, even if they are in a hidden menu. That's how they can be indexed, featured in sitemaps, breadcrumbs and have SEO friendly URLs assigned to them.

If you have a combination of public and private content then set the home page and any other public content to Public and leave the login module visible for users to use whenever they want to (like it is on the community and resource areas of joomla.org). Have a login menu item too if you want to, but don't make that the way to access the Fabrik list, do that using a separate menu item which has permissions set to Registered.

Thank you so much for all the great answers you give (y).
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top