XF 2.1 adding field to register form

shqawe

Member
Licensed customer
I would like to add gender field to register form so when user register he should to choose between male or female but i didn't find a way to save this to db

Can someone help in this?
 
Read the section titled Modifying the forum edit form in the docs. It explains how to use the template modification system which is what you need to do.

 
my dear @ozzy47 i already added the modification to register_form template but my problem now how can save this to database

I extended register controller with this code:

PHP:
protected function getRegistrationInput(\XF\Service\User\RegisterForm $regForm)
    {
        $input = parent::getRegistrationInput($regForm);
        $input['gender'] = $this->request->filter('gender' , 'int');

        return $input;
    }

Also i extended registration service with this code:

PHP:
public function setFromInput(array $input)
    {
        if (isset($input['gender']))
        {
            $this->user->gender = $input['gender'];

        }

      return  parent::setFromInput($input);
    }

Finally add column to user entity but when i try to register new user gender column doesn't affected.

So i'm sure i miss somthing but i don't know where.
 
@Bespoke Unfortunately it doesn't work and this is my Listener code:

PHP:
public static function userEntityStructure(\XF\Mvc\Entity\Manager $em, \XF\Mvc\Entity\Structure &$structure)
    {
        $structure->columns['gender'] = ['type' => Entity::INT, 'default' => 0];
    }
 
I assume that you've also added your gender column to the User table either manually or through a Setup file in your add-on.
If you are sure your template modification is actually working and is providing you with a value, then I have no idea why it is not working for you.
Are you getting any errors?
 
Back
Top Bottom