1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed Validator Problem

Discussion in 'Resolved Bug Reports' started by ragtek, Sep 8, 2011.

  1. ragtek

    ragtek Guest

    The Method controller::_validateField($dataWriterName, array $data = array()) doesn't work 100% as it should.

    It doesn't accept additional Data, which are set to the "normal" DataWriters.
    Because of this, sometimes the validator will show an error which shouldn't be shown and the datawriter will be saved sucessfull.

    For example:

    XenForo_ControllerAdmin_User

    If you edit an user from the acp, the dw have the Option OPTION_ADMIN_EDIT set to true, which will skip some validators

    PHP:
    $writer->setOption(XenForo_DataWriter_User::OPTION_ADMIN_EDITtrue);
    BUT, because of the js autovalidation , the script will call
    PHP:
        public function actionValidateField()
        {
            
    $this->_assertPostOnly();

            return 
    $this->_validateField('XenForo_DataWriter_User', array(
                
    'existingDataKey' => $this->_input->filterSingle('user_id'XenForo_Input::UINT)
            ));
        }
    And because of this we will get an validation error, because the dw doesn't skip the check (because of the missing OPTION_ADMIN_EDIT)!

    What about a 3. parameter, where we can set the options?

    PHP:
    public function actionValidateField()
        {
            
    $this->_assertPostOnly();

            return 
    $this->_validateField('XenForo_DataWriter_User', array(
                
    'existingDataKey' => $this->_input->filterSingle('user_id'XenForo_Input::UINT)
            ), array(
    XenForo_DataWriter_User::OPTION_ADMIN_EDIT));
        }
    instead of
    PHP:
        public function actionValidateField()
        {
            
    $this->_assertPostOnly();

            return 
    $this->_validateField('XenForo_DataWriter_User', array(
                
    'existingDataKey' => $this->_input->filterSingle('user_id'XenForo_Input::UINT)
            ));
        }
    and in controller::_validateField add the 3. parameter and inside

    PHP:
    protected function _validateField($dataWriterName, array $data = array(), array $options = array())
    ....
      if (!empty(
    $options)){
                foreach (
    $options AS $option    => $value)
                
    $writer->setOption($option$value);
            }
     

    Attached Files:

  2. Mike

    Mike XenForo Developer Staff Member

    I've added 2 arguments here, for the most flexibility:
    Code:
    protected function _validateField($dataWriterName, array $data = array(), array $options = array(), array $extraData = array())
     
    Fuhrmann and ragtek like this.
  3. ragtek

    ragtek Guest

    great:)
    thx
     

Share This Page