APF_Demo_AdvancedUsage_Verification_Field::replyToValidateField PHP Метод

replyToValidateField() публичный Метод

Validates the 'numeric' field in the 'field_verification' section of the 'APF_Demo' class.
public replyToValidateField ( $sNewInput, $sOldInput, $oAdmin )
    public function replyToValidateField($sNewInput, $sOldInput, $oAdmin)
    {
        /* 1. Set a flag. */
        $_bVerified = true;
        /* 2. Prepare an error array.
                We store values that have an error in an array and pass it to the setFieldErrors() method.
               It internally stores the error array in a temporary area of the database called transient.
               The used name of the transient is a md5 hash of 'instantiated class name' + '_' + 'page slug'. 
               The library class will search for this transient when it renders the form fields 
               and if it is found, it will display the error message set in the field array.     
           */
        $_aErrors = array();
        /* 3. Check if the submitted value meets your criteria. As an example, here a numeric value is expected. */
        if (!is_numeric($sNewInput)) {
            // $variable[ 'sectioni_id' ]['field_id']
            $_aErrors[$this->sSectionID]['numeric'] = __('The value must be numeric:', 'admin-page-framework-loader') . ' ' . $sNewInput;
            $_bVerified = false;
        }
        /* 4. An invalid value is found. */
        if (!$_bVerified) {
            /* 4-1. Set the error array for the input fields. */
            $oAdmin->setFieldErrors($_aErrors);
            $oAdmin->setSettingNotice(__('There was an error in a form field.', 'admin-page-framework-loader'));
            return $sOldInput;
        }
        return $sNewInput;
    }
APF_Demo_AdvancedUsage_Verification_Field