Does anyone have any thoughts about implementing a similar option for passing
form context information to filters as we do for validators?

in Zend_Form_Element (current implementations):

    /**
     * Validate element value
     *
     * @param  mixed $value
     * @param  mixed $context
     * @return boolean
     */
    public function isValid($value, $context = null)
    {
     ....
     }

    /**
     * Filter a value
     *
     * @param  string $value
     * @param  string $key
     * @return void
     */
    protected function _filterValue(&$value, &$key)
    {
        foreach ($this->getFilters() as $filter) {
            $value = $filter->filter($value);
        }
    }

change this to (adding context):

    protected function _filterValue(&$value, &$key, $context = null)
    {
        foreach ($this->getFilters() as $filter) {
            $value = $filter->filter($value, $context);
        }
    }

It would not have to be implemented this way. I am just trying to get the
point across. One of the caveats of this is that the form values might not
be filtered.

I raise this question because I wrote a validator for phone numbers. I would
like to submit this as a proposal soon. The X_Validator_Phone (I created)
takes into account Zend_Locale for the region. I currently have this
implemented for NANP: 

http://en.wikipedia.org/wiki/North_American_Numbering_Plan

http://en.wikipedia.org/wiki/Country_calling_code

I would like to filter phone numbers based on a country being selected in a
form. This would require the context information to be passed to the filter.

-- 
View this message in context: 
http://www.nabble.com/Pass-form-values-to-filters-tp23489986p23489986.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to