Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted May 13, 20204 yr Hey, I want to add a field to the registration form, just a normal text field to add to the core_members table and I will use this field on my app, Its the first time Im using hooks for my app. I know I need to hook to this class \IPS\core\modules\front\system\register but I cant make it work. I dont know to which function adds the fields. Please help, Thanks.
May 13, 20204 yr Solution Quick example, obviously not tested: /** * Build Registration Form * * @return \IPS\Helpers\Form */ public static function buildRegistrationForm( $postBeforeRegister = NULL ) { $form = parent::buildRegistrationForm( $postBeforeRegister ); $form->add( new \IPS\Helpers\Form\Text( 'field_name', NULL, TRUE ), 'password_confirm' ); return $form; } /** * Create Member * * @param array $values Values from form * @param array $profileFields Profile field values from registration * @param array|NULL $postBeforeRegister The row from core_post_before_registering if applicable * @return \IPS\Member */ public static function _createMember( $values, $profileFields, $postBeforeRegister = NULL ) { $member = parent::_createMember( $values, $profileFields, $postBeforeRegister ); $member->field_name = $values['field_name']; $member->save(); return $member; }
May 13, 20204 yr You may also want to consider using a profile field and then reading the value of that field in your application.
May 13, 20204 yr Author You may also want to consider using a profile field and then reading the value of that field in your application. The field I need has to be on the registration form, I couldn't find how to do it. Quick example, obviously not tested: /** * Build Registration Form * * @return \IPS\Helpers\Form */ public static function buildRegistrationForm( $postBeforeRegister = NULL ) { $form = parent::buildRegistrationForm( $postBeforeRegister ); $form->add( new \IPS\Helpers\Form\Text( 'field_name', NULL, TRUE ), 'password_confirm' ); return $form; } /** * Create Member * * @param array $values Values from form * @param array $profileFields Profile field values from registration * @param array|NULL $postBeforeRegister The row from core_post_before_registering if applicable * @return \IPS\Member */ public static function _createMember( $values, $profileFields, $postBeforeRegister = NULL ) { $member = parent::_createMember( $values, $profileFields, $postBeforeRegister ); $member->field_name = $values['field_name']; $member->save(); return $member; } It worked, excatly what I needed, thanks!
May 13, 20204 yr The field I need has to be on the registration form, I couldn't find how to do it. There’s an option in the profile field to make it appear in the registration screen.
May 13, 20204 yr Author There’s an option in the profile field to make it appear in the registration screen. Good to know, anyway I prefer your solution, this field wont show for the users anywhere after registering.
November 11, 20204 yr There’s an option in the profile field to make it appear in the registration screen. I don't think it is there any more with v4.5 @Adriano Faria cos if it is I can't find it
November 11, 20204 yr I don't think it is there any more with v4.5 @Adriano Faria cos if it is I can't find it It’s a bit confusing but it’s there. It depends on how your registration is set. If you use Quick Registration, then you’ll need to add it on a step of Profile Completion. If you use Full Registration form, then the option will appear in the profile field.