How to take a variable from event register before to register after?

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
aster59
Registered User
Posts: 80
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

How to take a variable from event register before to register after?

Post by aster59 » Sat Dec 30, 2017 10:50 pm

Hi again. Sorry, I can't seem to figure this part out now.

So I got this variable, $ref, I need to carry over to register after. It is like a referral ID so you can know when users come to the forum from someone. Here is my current code for the extension.

Scenario: someone goes to a forum with the link:
https://myforum.com/ucp.php?mode=register&ref=i_was_referred_by

Code with the following event processes:

Code: Select all


use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class points_listener implements EventSubscriberInterface {
	
	protected $template, $helper, $user, $db, $request;
	
	public function __construct(\phpbb\template\template $template,
							    \phpbb\controller\helper $helper,
							   	\phpbb\user $user,
							   	\phpbb\db\driver\driver_interface $db,
							   	\phpbb\request\request $request) 
	{
		$this->template  = $template;
		$this->helper    = $helper;
		$this->user      = $user;
		$this->db        = $db;
		$this->request   = $request;
	} 
	
    static public function getSubscribedEvents()
    {
        return array(
			'core.ucp_register_data_before'		   => 'ref_link_find',
        );
    }

    public function ref_link_find($event) {

    	$ref_link = $this->request->variable('HTTP_REFERER', '', false,\phpbb\request\request_interface::SERVER);
    	
    	$ref_pos = stripos($ref_link, 'ref=');
    	$ref_pos_end = $ref_pos + 4; //after = sign

    	$ref = substr($ref_link, $ref_pos_end); //actual ref code/number

    	if($ref_pos !== false) //if was referred by user - get this code to next event
    	{
    		//any ideas for what to do here?
    	}
    }

At the very end of this code, I basically need to get this $ref var from core.ucp_register_data_before to core.ucp_register_requests_after. Any ideas? It could be something in the $event variable, perhaps submit or data.

Thanks. This could be a cool extension.

aster59
Registered User
Posts: 80
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Re: How to take a variable from event register before to register after?

Post by aster59 » Mon Jan 01, 2018 10:51 pm

OK I Figured out how to get the $ref var to the next event. I just assigned it to an hidden input on the registration page.

Code: Select all

<input type="hidden" name="ref_by" value="{ref_by}">
I did a register append event to add this to the form and just pulled it from the template with request var.

Now I can't figure out if register after event is even right. I tried to do:

Code: Select all


//update new user registered as referred by this one!
    		$event['data'] = array_merge($event['data'], array(
    			'ref_by'	=> $u_referred_by_ID,
    		));

FYI: $u_referred_by_ID is the ID of the user that refer this user. Gotten with a few queries seeing the ref code put in.

I guess data submits? but it doesn't I guess because the ref_by doesn't fill in in my DB (called the same thing and is a varchar in my DB) after the user registers. Not sure which event to use but so close to being done with this...

User avatar
posey
Registered User
Posts: 706
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: How to take a variable from event register before to register after?

Post by posey » Thu Jan 04, 2018 1:17 pm

Not sure if this applies for you, but have a look here:
https://area51.phpbb.com/docs/dev/3.2.x ... -listeners
phpBB3.2.x Documentation wrote:Note how the lang_set_ext event variable is first copied by assigning it to a local variable, then modified, and then copied back. This shortcut does not work: $event['foo']['bar'] = $baz; This is because the event variables are overloaded, which is a limitation in PHP.
''I'm pretty sure there's a lot more to life than being really, really, ridiculously good looking. And I plan on finding out what that is.''

aster59
Registered User
Posts: 80
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Re: How to take a variable from event register before to register after?

Post by aster59 » Thu Jan 04, 2018 5:37 pm

posey wrote:
Thu Jan 04, 2018 1:17 pm
Not sure if this applies for you, but have a look here:
https://area51.phpbb.com/docs/dev/3.2.x ... -listeners
phpBB3.2.x Documentation wrote:Note how the lang_set_ext event variable is first copied by assigning it to a local variable, then modified, and then copied back. This shortcut does not work: $event['foo']['bar'] = $baz; This is because the event variables are overloaded, which is a limitation in PHP.
That did not work.

I think it is simply the wrong event.

Check UCP registration data after they are submitted
https://wiki.phpbb.com/Event_List#core. ... data_after

I need to I guess just assign the value to a custom profile field with the before event to submit it to DB instead of migrated field I created.. There seems to be no event before submission that I can grab a sql_arr.

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 20784
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: How to take a variable from event register before to register after?

Post by RMcGirr83 » Thu Jan 04, 2018 5:41 pm

Take a look at this listener from an extension. You want to look at the ucp_register_x events.

https://github.com/rmcgirr83/phpBB-3.1- ... stener.php
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

aster59
Registered User
Posts: 80
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Re: How to take a variable from event register before to register after?

Post by aster59 » Fri Jan 05, 2018 5:10 pm

RMcGirr83 wrote:
Thu Jan 04, 2018 5:41 pm
Take a look at this listener from an extension. You want to look at the ucp_register_x events.

https://github.com/rmcgirr83/phpBB-3.1- ... stener.php
Oh wow. core.ucp_register_user_row_after is it.
The language describing it just went over my head for some reason. Thank you!

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 20784
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: How to take a variable from event register before to register after?

Post by RMcGirr83 » Fri Jan 05, 2018 5:21 pm

You're welcome! :)
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 7 guests