XF 2.0 Adding a checkbox on register_form

BoostN

Well-known member
I'm having a little bit of diffcuiltly capturing input from my custom field that sets inside the User Option entity. I'm looking at extending the XF\Pub\Controller\Register class and I'm thinking I should do the following:

PHP:
<?php

namespace BoostN\SendySync\XF\Pub\Controller;

class Register extends XFCP_Register
{
    
    protected function setupRegistration(array $input)
    {

        $input += $this->filter([
            'option' => [
                'my_colum' => 'bool'
        ]]);

        return parent::setupRegistration($input);
    }

}

When I check the box and submit, it saves to the DB as empty. Any pointers or hints at what I need to do next?
 
I'm revisiting this add-on I'm developing.. still stuck on this. The column is saved to the xf_user_option table..

I've also tried to extend the getRegistrationInput code in the XF\Pub\Controller\Register class..

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

    return $input;
}

Any advise?
 
I resolved this by extending both XF\Service\User\Registration and XF\Pub\Controller\Register. Seems to be working now.
 
@BoostN It will be a very helpful if you share full code because i have same issue special registration service code if you don't mind

Thanks in advance
 
@BoostN It will be a very helpful if you share full code because i have same issue special registration service code if you don't mind

Thanks in advance

Sure, does this help?

PHP:
<?php

namespace BoostN\SendySync\XF\Pub\Controller;

use XF\ConnectedAccount\Provider\AbstractProvider;
use XF\ConnectedAccount\ProviderData\AbstractProviderData;
use XF\Mvc\ParameterBag;

class Register extends XFCP_Register
{
    protected function getRegistrationInput(\XF\Service\User\RegisterForm $regForm)
    {
        $input = parent::getRegistrationInput($regForm);
        $input['boostn_sendysync_option_optin'] = $this->request->filter('boostn_sendysync_option_optin' , 'bool');

        return $input;
    }
}

That captures the data on the registration form, and saves back to the DB on submission.

Also:

PHP:
<?php

namespace BoostN\SendySync\XF\Service\User;

class Registration extends XFCP_Registration
{
    public function setFromInput(array $input)
    {
        if (isset($input['boostn_sendysync_option_optin']))
        {
            $this->setSendyStatus($input['boostn_sendysync_option_optin']);

        }

        parent::setFromInput($input);
    }

    public function setSendyStatus($choice)
    {
        $this->user->Option->boostn_sendysync_option_optin = $choice;

    }
}
 
Thanks man to share the code but unfortunately it doesn't work with me :cautious: maybe because my data is an array?

or maybe my entity hint to XF\Entity\UserOption is wrong?
 
Top Bottom