How to allow a form to be seen only after Login in Joomla
Hello all,
I created a form in chronoforms, now i want it to be displayed only after the user login. Could anyone help me to code this?🙂 Any help will be appreciated!
Joe
I created a form in chronoforms, now i want it to be displayed only after the user login. Could anyone help me to code this?🙂 Any help will be appreciated!
Joe
Hi joe,
Add this code to beginning of the Form HTML in CFv3 or into a Custom Code action in CFv4
Replace 'error' with 'info' or 'alert' to change the message format.
Leave the message string out - just use $mainframe->redirect('index.php'); to redirect silently
Bob
Add this code to beginning of the Form HTML in CFv3 or into a Custom Code action in CFv4
<?php
$user =& JFactory::getUser();
if ( !$user->gid ) {
$mainframe =& JFactory::getApplication();
$mainframe->redirect('index.php', 'You are not allowed to access this page', 'error');
}
?>
Replace 'index.php' with some other url to redirect to the user there.Replace 'error' with 'info' or 'alert' to change the message format.
Leave the message string out - just use $mainframe->redirect('index.php'); to redirect silently
Bob
Hi Greyhead,
Thanks for your reply, I created the custom code section as you suggested. However, the form doesn't display at the frontend and shows "HTTP 500 internal server error". Could you help me out again?
Many Thanks
Joe
Thanks for your reply, I created the custom code section as you suggested. However, the form doesn't display at the frontend and shows "HTTP 500 internal server error". Could you help me out again?
Many Thanks
Joe
Ho Joe,
My apologies. Please replace
Bob
PS I updated my earlier post
My apologies. Please replace
$mainframe =& JFactory::getFramework();
with$mainframe =& JFactory::getApplication();
I must remember which one is correct :-(Bob
PS I updated my earlier post
Thanks a lot GREYHEAD! You are a hero! It works really nice, I am happy to see your reply in the forum, because it is like a solution bank!😀
Joe
Joe
Hello Greyhead,
Regarding to the above code you posted, i forgot to mention that i replaced the code below
with
It then works fine, otherwise i keep on getting redirected back to index.php even if i logged in. I am using Joomla 1.6, is this error occured because of the version inconsistency? Just a guess. Anyways, thank you a lot for all your time and help!:D
Joe
Regarding to the above code you posted, i forgot to mention that i replaced the code below
if ( !$user->gid ) {
...
...
...
}
with
if ( !$user->username) {
...
...
...
}
It then works fine, otherwise i keep on getting redirected back to index.php even if i logged in. I am using Joomla 1.6, is this error occured because of the version inconsistency? Just a guess. Anyways, thank you a lot for all your time and help!:D
Joe
This topic is locked and no more replies can be posted.