redirect plugin

gapper

Member
Hi,

how can I use the redirect plugin only if users aren't registered? In other words, how can I let appear a message asking for registration for forms opened by not registered users?

Is there a redirect plugin for lists?
 
You can use the 'condition' part of the redirect plugin to fire it only if the user is not registered

PHP:
$user = JFactory::getUser();
return $user->get('id') === 0;
 
Hi Rob,
thanks.
I did as you wrote, so I copied and pasted the code (the 2 lines above) in the Condition part / Published: Yes / in Jump page I typed the message I would have wanted showing.
The redirect page doesn't appear for not registered.
I did no replacement in the code. I only copied and pasted without amendments. Is it correct?
 
Sorry I made a mistake with my previous attempt, so I tried the following:
Jum page: empty
Append jump url with data: No
Submission message: I have written a customized message
Condition: I copied and pasted the code in your previous message (without amendments)
Content Reset: Yes


If I try to open the frontend of my local web without logging as administrator and neither as user, then my customized message doesn't appear
 
I think what you want is to have a redirect BEFORE the form is loaded and not AFTER? Can you clarify what you want to do (because you talk about a redirect plugin for list....)
 
The redirect should be BEFORE the form appearing. If the user clicking the menu is registered, then he can see the form. If he is not registered, then he can't see the form.
 
That's what I thought.
In that case, the redirect plugin won't help as it works on submitting the form.

What you need is a PHP form plugin in the form you want to "protect". Set the plugin to run on New, set "process script" to "Before the form is loaded", and in the PHP bow, write :
PHP:
$user = JFactory::getUser();
if($user->get('guest') == 1)
{
$app = JFactory::getApplication();
$url = 'url_of_your_registration_form';
$msg = 'You have to be registered to fill this form';
$app->redirect($url, $msg);
}

The 'url_of_your_registration_form' should be a relative path (starts with "index.php?...").
 
Thanks so much for the PHP code.
I have copied the code and replaced the url and the message.
When I click on the menu, the following page appears:
Webpage has produced a redirect loop
The webpage has caused too many redirects. The cookie deleting corresponding to this site or the third parties cookies activation could solve the problem. Otherwise, it could be a server configuration problem and not the computer.


I am working on local web. I have deleted history and cookies, but that error is always appearing. I am attaching a snapshot showing the error number.
 

Attachments

  • Error 310.jpg
    Error 310.jpg
    10.3 KB · Views: 285
Are you sure that the url you put in the redirect code is the one of the regitration form? It HAS to be different from the url of the form where you put the plugin of course because otherwise you are endlessly redirecting the form to itself.
 
really though what you want to do is set the list's Access setttings to stop users from being able to add records. no need to write custom code
 
I have already done it, but by using only the Access settings into the list, the form however appears, but it can't be filled.
What I wanted is not show the forms content, not only to avoid not registered users can fill them.

Hope that makes sense!
 
If the user clicking the menu is registered, then he can see the form. If he is not registered, then he can't see the form.
So why do you show the menu item to the public user? Set the menu access to registered.
And maybe create an other menu item only visible to non-registered users showing a message "please register" or going directly to the registration form.
 
That was the solution I used before knowing the PHP code for PHP form plugin.
The reason I would want to let see some menu items is to allow not registered users to know the possibilities offered by the website.
 
Sorry, I changed my idea:
I would want to let appear the login module (user and password fields, password forgotten and registration links) instead of only the registration form.
What could the PHP code be?
 
I'm a bit lost on this one, could you go into a bit more detail what it is you would now like to do? For example is the registration form a Fabrik form?
Why not just add the login module to the registration page using the usual Joomla module assignment?
thx
Rob
 
Yes, the registration form is a Fabrik form. At present time when users click a link and they are not registered, then the registration form (a fabrik registration form) appears. It is ok, but
I have thought that some users can be already registered, but they can access to the link through a search engine and not from the website homepage. If they are already registered and if they access to the page through a search engine, they could login through the usual joomla login module.
Therefore I would want to replace the registration form appearing (when users click on a link and they are not registered) with the traditional joomla login module appearing because the traditional joomla login module include a link: "Register" which can be clicked if users are not registered.
Please let me know if it makes sense.
 
So, it sounds like if they hit the page with your form on it, and they aren't logged in, then you want them to be redirected to the standard J! login page?

Remember there is a difference between "registered" and "logged on". registered just means they have an account. But if they aren't logged on to the site, we don't know if they are registered or not.

So you need to be careful in your wording of what you want, between using "registered" and "logged on".

-- hugh
 
Thanks. Yes. If they hit the page with my form on it, and they aren't logged in, then I want them to be redirected to the standard J! login page.
Sorry in my wording of what I want. I mean "logged on".
 
In which case, I think the code that JFQ gave you in post #7 should work, just replace 'url_of_your_registration_form' with the URL of your standard J! login page.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top