The field 'silverpopintegration_subscription' was not recognised.

Radi

Member
When I try to save to xf_user_option I get this: "The field 'silverpopintegration_subscription' was not recognised."

Here is my code:
PHP:
class SilverpopIntegration_XenForo_ControllerPublic_Account extends XFCP_SilverpopIntegration_XenForo_ControllerPublic_Account {
    public function actionEmailPreferencesSave() {
        $this->_assertPostOnly();

        $visitor = XenForo_Visitor::getInstance();

        if (!$visitor->canEditProfile()) {
            return $this->responseNoPermission();
        }

        $settings = $this->_input->filter(array(
            //user_option
            'silverpopintegration_subscription' => XenForo_Input::UINT,
        ));

        $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
        $writer->setExistingData(XenForo_Visitor::getUserId());
        $writer->bulkSet($settings);
        //$writer->setCustomFields($customFields, $customFieldsShown);
        $writer->preSave();

        if ($dwErrors = $writer->getErrors()) {
            return $this->responseError($dwErrors);
        }

        $writer->save();

        return $this->responseRedirect(
            XenForo_ControllerResponse_Redirect::SUCCESS,
            $this->getDynamicRedirect(XenForo_Link::buildPublicLink('account/email-preferences'))
        );

    }
}

PHP:
class SilverpopIntegration_XenForo_DataWriter_User extends XFCP_SilverpopIntegration_XenForo_DataWriter_User {

    /**
    * Gets the fields that are defined for the table. See parent for explanation.
    *
    * @return array
    */
    protected function _getFields() {
        $fields = parent::_getFields();
        $fields['xf_user_option']['silverpopintegration_subscription'] = array('type' => self::TYPE_BOOLEAN, 'default' => 1);

        Zend_Debug::dump($fields);

        return $fields;
    }
}


PHP:
class SilverpopIntegration_Listener {
    /**
    *
    * @var XenForo_ControllerRegister_Register::actionRegister
    */
    public static $register;

    public static function loadControllers($class, array &$extend) {
        static $controllers = array(
            'XenForo_ControllerPublic_Account',
            //'XenForo_ControllerPublic_Register',

            //'XenForo_ControllerAdmin_Tools',
            //'XenForo_ControllerAdmin_Option',

            'XenForo_DataWriter_User'
        );

        if(in_array($class, $controllers)) {
            $extend[] = 'SilverpopIntegration_' . $class;
        }
    }
}





My SilverpopIntegration_XenForo_ControllerPublic_Account works, so that should mean that my Controllers listener is working fine. SilverpopIntegration_XenForo_DataWriter_User does not seem to be loading at all.

What is going on?

Please help!
 
Are you sure SilverpopIntegration_XenForo_DataWriter_User is being loaded? Try throwing a die('test'); into the _getFields().

I do see that your function is called loadControllers. Make sure you aren't using the load_class_controller code event for that.
 
Are you sure SilverpopIntegration_XenForo_DataWriter_User is being loaded? Try throwing a die('test'); into the _getFields().

I do see that your function is called loadControllers. Make sure you aren't using the load_class_controller code event for that.
That was it.

I added load_class_datawriter and used the same class::method and it worked! Thank you man!
 
@Jake B. do you have any idea why

$settings = $this->_input->filter(array('silverpopintegration_subscription' => XenForo_Input::UINT));

is not getting populated from my form?
 
I am testing now with $writer->set('silverpopintegration_subscription', $this->_input->filterSingle('silverpopintegration_subscription', XenForo_Input::BOOLEAN)); but still not good.

here is my form:
HTML:
<xen:title>{xen:phrase silverpopintegration_email_preferences}</xen:title>

<xen:require css="silverpopintegration_account_email_preferences.css" />

<form method="post" class="xenForm formOverlay NoFixedOverlay AutoValidator"
    action="{xen:link 'account/email-preferences-save'}"
    data-fieldValidatorUrl="{xen:link 'account/validate-field.json'}"
    data-redirect="yes">

    <h3 class="sectionHeader">{xen:phrase silverpopintegration_options}</h3>

    <xen:hook name="silverpopintegration_account_email_preferences_options">
    <dl class="ctrlUnit">
        <dt></dt>
        <dd>
            <ul>
                <li>
                    <label for="silverpopintegration_subscription"><input type="checkbox" name="visible" value="1" id="silverpopintegration_subscription" class="OptOut Disabler" {xen:checked "{$silverpopintegration_subscription}"} /> {xen:phrase silverpopintegration_subscription}</label>
                    <p class="hint">{xen:phrase silverpopintegration_subscription_hint}</p>
                    <!--<ul id="silverpopintegration_subscription_weekly">
                        <li>
                            <label><input type="checkbox" name="activity_visible" value="1" class="OptOut" {xen:checked $silverpopintegration_subscription} /> {xen:phrase show_your_current_activity}</label>
                            <p class="hint">{xen:phrase this_will_allow_other_people_to_see_what_page_you_currently_viewing}</p>
                        </li>
                    </ul>-->
                </li>
            </ul>
            <xen:if is="!{$xenOptions.swfUpload}">
                <input type="hidden" name="enable_flash_uploader" value="{xen:if $visitor.enable_flash_uploader, 1, 0}" />
            </xen:if>
        </dd>
    </dl>

    </xen:hook>

    <dl class="ctrlUnit submitUnit">
        <dt></dt>
        <dd><input type="submit" name="save" value="{xen:phrase save_changes}" accesskey="s" class="button primary" /></dd>
    </dl>

    <input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
</form>
 
I found my error. I copied the code and never updated the input name...

I am able to update the DB, but now I am not able to retrieve the value from it.

EDIT: I found a work around that by using $visitor['silverpopintegration_subscription'], but would like to know what I am doing wrong? Do I need to extend XenForo_Model_User and setup some methods in there?
 
Last edited:
Top Bottom