Jump to content

Adding a field to registration


Go to solution Solved by Adriano Faria,

Recommended Posts

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.

Link to comment
Share on other sites

  • 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;
	}

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 5 months later...
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. 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...