iSE Posted December 10, 2009 Share Posted December 10, 2009 Hi All, I'm using the php filter functions to validate my form data. For custom filters, I'm using the FILTER_CALLBACK filter but when I'm using files, this never seems to be called? It may be that the filters are not designed to be called for files but I can't find any documentation to support that. Anybody know anything about this? iSE Quote Link to comment https://forums.phpfreaks.com/topic/184625-filter_callback-files/ Share on other sites More sharing options...
trq Posted December 10, 2009 Share Posted December 10, 2009 It may be that the filters are not designed to be called for files but I can't find any documentation to support that. I can't find any documentation that doesn't support that. Looking at the extension, I'm not sure its designed to handle files. What exactly are you trying to filter? Can we see one of your callbacks? Quote Link to comment https://forums.phpfreaks.com/topic/184625-filter_callback-files/#findComment-974644 Share on other sites More sharing options...
iSE Posted December 10, 2009 Author Share Posted December 10, 2009 Well that's not surprising as I can find very little documentation on the filters as it is. I add rules, forwhich is gets the filter argument to add to the filter argument array when calling: filter_input_array($this->_inputType, $this->_filterArgs); Everything works fine. The filter argument for each rule object which uses callbacks is: <?php public function getFilterArgument() { return array('filter' => FILTER_CALLBACK, 'options' => array($this, 'callbackFunction')); } ?> Then the callback function will be (for example, checking the length of a string): <?php public function callbackFunction($string) { // Check arguments if (!is_string($string)) throw new InvalidArgumentException('Form_Rule_Length::callbackFunction() expects a string as the first argument; ' . gettype($string) . ' given.'); // Check length if (isset($this->_min)) if (strlen($string) < $this->_min) return false; if (isset($this->_max)) if (strlen($string) > $this->_max) return false; // Must be valid if reached here return $string; } ?> This all works fine, when I use a callback for a file, i can get to the getFilterArgument() method, but the callback method is NEVER called on filter_input_array. iSE Quote Link to comment https://forums.phpfreaks.com/topic/184625-filter_callback-files/#findComment-974662 Share on other sites More sharing options...
salathe Posted December 10, 2009 Share Posted December 10, 2009 filter_input_array only filters GET, POST, cookie, server, env, session or request data. Quote Link to comment https://forums.phpfreaks.com/topic/184625-filter_callback-files/#findComment-974675 Share on other sites More sharing options...
iSE Posted December 10, 2009 Author Share Posted December 10, 2009 What I was trying to do was add a dummy $_POST[$fieldName] value hoping this would force the callback method to be called. However, filter_input_array, uses a copy of the input array BEFORE the script is run, so any changes to POST don't reflect in the filter_input_array values to be filtered. I changed from filter_input_array to use filter_var_array, and used the superglobal as the input array. Works fine now. Is a bit annoying that it works this way but what can you do. Thanks for your help guys. Quote Link to comment https://forums.phpfreaks.com/topic/184625-filter_callback-files/#findComment-974680 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.