Goal: assign a member to a group, based upon the value of a custom registration field. Hook: member_register_validate_members
Ok, so I created an extension based upon different forum threads. I attached the file.
Situation: I register a testuser (frontend) I receive the activation email I click the link which brings me to “http://site.com/index.php?ACT=8&id=9DcfuWIsUE”
The following lines of code should give me the member_id, so I can get the value of my custom field (m_field_id_3 from exp_member_data).
$authcode = $_GET['id']; //get te authcode from URL
$resultaat = $DB->query("select member_id from exp_members where authcode = $authcode"); //get member_id
$current_member_id = ($resultaat->row['member_id']);
Problem: The query doesn’t seem to do anything. No value is returned, even if I fill in the authcode by hand (when I run it on the mysql shell it returns the member_id as it should be, so the record is there!)
Hope anybody can help me out with this. Thanks!
Not 100% sure you can just use the GET variable like that in EE.
Try something like this:
global $IN;
$authcode = $IN->GBL('id'); //get te authcode from URL
$resultaat = $DB->query("select member_id from exp_members where authcode = '".$DB->escape_str($authcode)."'"); //get member_id
$current_member_id = ($resultaat->row['member_id']);
Aha, yes that old chestnut… If you inspect the code around where this hook is implemented you will see that the authcode is emptied just before the hook is called. I have an FR for moving that single line of code to below the extension call, please add your voice 😊. (A workaround is to just move that line of code to below the extension call)
the GET variable isn’t the problem, works fine when I grab it from the URL and echo it. The problem is the query: doesn’t seem to return anything, even if I fill in the authcode by hand like this:
$resultaat = $DB->query("select member_id from exp_members where authcode = 'CODE_HERE'"); //get member_id
echo "test ".$current_member_id = ($resultaat->row['member_id']);
behind the echo there’s nothing…and this query really should return the member_id
edit Ah sorry, now I get it. The auth code is emptied from the database just before the hook..doh..that is what you meant.
So, any other way to get the member id at that moment in the extension function?
edit 2 Ah nevermind, I already moved the hook above the cleanup 😊 Thanks!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.