Hi guys,
I need to hide a form if the user is not registered.
I need to do it with code, cause the form is not a published page but accessible through a fake select form, that act as a menu, launching a link at the different options.
I was thinking a check with the userID, if the userID is =<0, the page will not shown and a message will appear instead.
How to not display the page?
Should the code go in server validation or whereelse?
How to call teh message of Joomla: you should be login to access this private area?
I need to hide a form if the user is not registered.
I need to do it with code, cause the form is not a published page but accessible through a fake select form, that act as a menu, launching a link at the different options.
I was thinking a check with the userID, if the userID is =<0, the page will not shown and a message will appear instead.
How to not display the page?
Should the code go in server validation or whereelse?
How to call teh message of Joomla: you should be login to access this private area?
Hi gg4,
In the beginning of the form html
Bob
In the beginning of the form html
<?php
$user = JFactory::getUser();
If ( $user->id == 0 ) {
global $mainframe;
$mainframe->enqueuemessage('Tough luck', 'error');
$mainframe->redirect('index.php');
}
?>
NB Not tested and may need debugging!Bob
Perfect Greyhead, just there was just typo for $mainframe, here the corrected code for copy paste for everybody 😀
To hide a form if user is not logged:
So I guess $mainframe is the global variable you use to communicate with the content area in Joomla.. is it?
Useful to know.
To hide a form if user is not logged:
<?php
$user = JFactory::getUser();
If ( $user->id == 0 ) {
global $mainframe;
$mainframe->enqueuemessage('Tough luck', 'error');
$mainframe->redirect('index.php');
}
?>
So I guess $mainframe is the global variable you use to communicate with the content area in Joomla.. is it?
Useful to know.
Hi gg4j,
Sorry about the typo - I fixed my version too (I missed the $ from $mainframe in a couple of places).
$mainframe isn't really the way to communicate with *content* but it does have some useful methods that allow you to comunicate with the Joomla system (or better the Framework). See here for more.
Bob
Sorry about the typo - I fixed my version too (I missed the $ from $mainframe in a couple of places).
$mainframe isn't really the way to communicate with *content* but it does have some useful methods that allow you to comunicate with the Joomla system (or better the Framework). See here for more.
Bob
This topic is locked and no more replies can be posted.