I’ve been through the documentation but am struggling a little with my first extension.
I want to create an extension that makes it possible to specify a redirect for the success page of the front end member registration form.
I have successfully set up the Extension and the settings are ok in terms of uninstalling and installing.
What I’m not clear on is writing the actual logic that takes over.
It is this chunk of code that does the work in mod.member_register.php
$data = array( 'title' => $LANG->line('mbr_registration_complete'),
'heading' => $LANG->line('thank_you'),
'content' => $LANG->line('mbr_registration_completed')."\n\n".$message,
'redirect' => '',
'link' => array($return, $site_name)
);
If I hard code the following line in mod.member_register.php it redirects on registration to the BBC
'redirect' => 'http://www.bbc.co.uk',
But I’d rather use an extension. I see the hook member_member_register there but I’m not sure how to override the variable in mod.member_register.php.
I have associated a method with my extension - is a method just a standard PHP function that is run after mod.member_register.php?
I realise this is a bit Hello World but hopefully I’ll get it after this!
Hi Shape,
I’m certainly no expert but perhaps I can help a little bit. Firstly, a method is the function in your extension that is going to be called when the extension hook is activated.
I’m sure that someone with more knowledge than me will jump in but what happens when your extension is called is that the processing ‘jumps’ out of mod.member.php and into your extension. What is crucial to understand is what the
$EXT->end_script
variable does. If in your method you set this variable to TRUE then when your method ends and processing is returned to the mod.member.php script the current PHP function will be completed i.e. in this case Send user notifications, Send email, Log user in, Create a new session, Update existing session variables, Update stats, and Build the message will not be run. So, I think you could copy all those bits of code right down to about line 837 (when that function ends) and put them in your extension. Then just change the redirect key in the
$data
array in your extension.
I hope I’ve not just confused you more (or given you duff info).
Cheers
Dry
I think you might just be in luck, actually. Tonight i’m updating a client site and removing ‘hacks’ replacing with extensions. The one i’m just doing now is to automatically log members in when they click on the activation link in their email and redirect to a template after that.
I’m sure without too much effort you’ll be able to remove the logging in part of the code, so to just custom redirect on activation.
Here you are shape, I removed the auto login code, since that did still need a change of one line to the core code unfortunately :(
Redirect settings are in the… settings ;]
Edit: It’s just occurred to me that this might not actually be what you were after… but hey it’s so simple you should be able to use it as an example to work with 😊
Well I’ve managed to create the extension and it is all working pretty well other than one thing.
The extension takes over at the member_member_register hook in mod.member_register and all it really does is define redirect in the $data array. This works fine and redirects back three pages in the user’s history.
Member Activation is set to No Activation Required and this works fine with the extension disabled, logging the user in ok.
With the extension enabled though everything works as expected other than the user being logged in. In other words the user is not logged in!
I’ve attached the extension to date - I have not added settings in until the debugging is complete. Am I missing something glaringly obvious?
Hello, Am I able to specify a page to redirect to after the registration is complete? Thanks Much!
Hmmm (thinking cap goes on!! 😊 ).
If I am thinking correctly then this would be a little tricky as the user may register and then not check their e-mail for a few days or so. This would mean that you would need a way to store where you want them to be re-directed to upon registration. If this was one same URL for everyone then that wouldn’t be a problem as you can easily re-direct someone to a certain page upon login using the exceptionally simple extension that I made here.
If on the other hand you would like to re-direct people to different pages as they probably would have registered from a single entry page and they may all land on different single entry pages then you are going to need to handle things slightly differently.
You would need to write the URL to a database table that you want to re-direct to upon the user finishing the registration process. I’m not sure but I should think that one of the registration hooks could be used here to grab the member_id of the registration process (hopefully they do have one at that moment - before they click on the e-mail confirmation that is) and use that along with the URL to write it into the database then upon registering using the e-mail link an extension would re-direct them to the URL stored in the database table saved for that member_id.
Just my thoughts. It all depends though on how the member registration process works. I’m not too sure where the details are held whilst the user is in limbo, that is before they have clicked on the e-mail link. If they are held in the normal member database tables then this should be do-able (he says fingers crossed!! 😊 )
Hope that brings some ideas to the front of lobes!! 😊
Best wishes,
Mark
Hiya,
Just did a quick test by registering an account on a DEV server but didn’t click on the e-mail registration link. The user details do indeed get stored to the normal database tables so if there are enough hooks and the right ones in the registration process then you should be able to hook in there and take over for a little while and find out the new member_id and also remember the URL you want to re-direct to and write those to a database table used for this purpose. Then once the user does indeed finally finish the registration process using the e-mail link then you can utilise this information to log them back in to the page they were previously on.
I think this would be a good addition for people who register using the e-mail link fairly quickly but it might (depending on the site design) confuse users who don’t finish the registration process for some days. All down to user preference though I suppose. Should be do-able though if there are enough extension hooks.
Best wishes,
Mark
jschutt,
Mark is correct. Members who have not clicked their activation link are still in the DB, they are just set to a Pending status. So if you wanted to get at that data in some way through an extension you would be able to provided there is a currently a hook in a post that would allow for whatever you want to do.
Jamie
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.