Gil Ronen Posted May 13, 2020 Posted May 13, 2020 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.
Solution Adriano Faria Posted May 13, 2020 Solution Posted May 13, 2020 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; }
Stuart Silvester Posted May 13, 2020 Posted May 13, 2020 You may also want to consider using a profile field and then reading the value of that field in your application.
Gil Ronen Posted May 13, 2020 Author Posted May 13, 2020 14 minutes ago, Stuart Silvester said: 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. 1 hour ago, Adriano Faria said: 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!
Adriano Faria Posted May 13, 2020 Posted May 13, 2020 Just now, Gil Ronen said: 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.
Gil Ronen Posted May 13, 2020 Author Posted May 13, 2020 1 hour ago, Adriano Faria said: 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.
ibaker Posted November 11, 2020 Posted November 11, 2020 On 5/14/2020 at 2:11 AM, Adriano Faria said: 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
Adriano Faria Posted November 11, 2020 Posted November 11, 2020 5 hours ago, ibaker said: 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. ibaker, bfarber and usmf 1 2
Recommended Posts