Assigning value to user table field during registration

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
Kami-sama
Registered User
Posts: 104
Joined: Sat May 26, 2018 3:07 pm

Assigning value to user table field during registration

Post by Kami-sama » Wed Jul 04, 2018 11:59 pm

Hey guys! So, long story short:

- my main goal is to assign variable X to custom user table field
- my extension adds extra fields to registration form
- Javascript calculates input values of those fields and returns variable X

My questions would be:
- how should I call the Javascript in such case? (with default registration submit button?)
- should it return result to registration hidden field so that information would be saved? Or should I send the variable X manually with php after JS is completed?

First time doing something like this. So not sure how the info is actually sent/ created during registration. Any ideas?

User avatar
MarkDHamill
Registered User
Posts: 3508
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: Assigning value to user table field during registration

Post by MarkDHamill » Thu Jul 05, 2018 2:09 am

Have you been through the how to create an extension tutorial?
Get the latest versions of my Digests and Smartfeed mods and extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
david63
Jr. Extension Validator
Posts: 14944
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Assigning value to user table field during registration

Post by david63 » Thu Jul 05, 2018 5:56 am

Without seeing your code (do you have a GitHub account?) it is difficult to say but I suspect you may need to use an Ajax return via phpBB routing method.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3300
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Assigning value to user table field during registration

Post by kasimi » Thu Jul 05, 2018 6:43 am

Use a hidden field. Subscribe to the core.ucp_register_data_after event to grab the data from the request and add it to the event's data (users table) or cp_data (profile fields table) array, depending on where the data should be stored.

User avatar
Kami-sama
Registered User
Posts: 104
Joined: Sat May 26, 2018 3:07 pm

Re: Assigning value to user table field during registration

Post by Kami-sama » Thu Jul 05, 2018 9:49 am

MarkDHamill wrote:
Thu Jul 05, 2018 2:09 am
Have you been through the how to create an extension tutorial?
Hey, yes, but it says nothing about registration form and how it works ;)


david63 wrote:
Thu Jul 05, 2018 5:56 am
Without seeing your code (do you have a GitHub account?) it is difficult to say but I suspect you may need to use an Ajax return via phpBB routing method.
Hey. I have seen similar examples done with other extensions (which include fields to registration form). My concern is how do I call and return my variable from JS.


kasimi wrote:
Thu Jul 05, 2018 6:43 am
Use a hidden field. Subscribe to the core.ucp_register_data_after event to grab the data from the request and add it to the event's data (users table) or cp_data (profile fields table) array, depending on where the data should be stored.
Hey. Yes, thinking to do the same. SO you think I should call JS with default submit button and return value to hidden field?

User avatar
Kami-sama
Registered User
Posts: 104
Joined: Sat May 26, 2018 3:07 pm

Re: Assigning value to user table field during registration

Post by Kami-sama » Fri Jul 06, 2018 10:29 am

So coming back to this. I assume I need event in the listener something like this?

Code: Select all

public function user_x_sql($event)
	{
		$event['sql_ary'] = array_merge($event['sql_ary'], array(
				'user_x' => $event['data']['user_x'],
		));
	}
As for subscriptions, I've seen these examples, do I need all of them?

Code: Select all

'core.ucp_register_data_before'			
'core.ucp_register_data_after'			
'core.ucp_register_user_row_after'	

EDIT: I ended up using 'core.ucp_register_user_row_after' and works great! value generated and assigned to DB. Now just need to test with the field hidden from registration view.

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 8 guests