How to check the value of a checkbox on registration

Randall

Member
I added a new checkbox on the registration form/template to allow our users to opt-in to an external service. I could use some help on how or where to check the value of that new checkbox. So, if they check the new checkbox I will create an account on an external website (creating the account is already done and working, I just want to give them the option), if not they need to follow the normal xenforo registration process. Would I use an event listener to check the value of that new checkbox?
 
You'd extend the controller where the register thing is done. XenForo_ControllerPublic_Register. At a quick glance, actionRegister is where you want to be doing your external registration. You also want to add your field into the data using _getRegistrationInputData, so you can access it in actionRegister (_getRegistrationInputDataSafe). Don't save it in the data key if you don't want to save it into the db for further use, set a new key. If you want to store if the user chose to create a new account on registration in the db, you will also need to be editing the DataWriter (XenForo_DataWriter_User) and add a field, as well as a database column, and in this case save the value into the data key along with the rest.

I hope that makes sense. To sum it up, extend the controller, filter the data thru using XenForo_Input in the right function, use that data in actionRegister() and call your create new account thing (assuming it's in a model) if you want to create a new account (assuming the checkbox is checked).

Oh, and to get the actual value of the checkbox, filter the data as UINT and just check if it's empty or not. By default, unchecked it should be 0 (thanks Chris, for informing that), set the value (if checked) to 1. That's a pretty easy way to do it, then just check if it's empty or not.
 
I would

- add a new profile field "external account"
- create a custom callback for this profile field

The callback creates or removes the external account.
 
Back
Top Bottom