ZF-11855: Zend_Filter_PregReplace does not have a valid MatchPattern set (Array of matches)


When PregReplace filter is applied to a Zend_Form_Element_* it presents a strange behavior during match and replace.

Zend_Filter_PregReplace basically resumes itself to apply a "preg_replace()" on line 171 as shown below.

preg_replace($this->_matchPattern, $this->_replacement, $value);

preg_replace allows the use of arrays for the MATCH and REPLACEMENT variables.

When performing the following code, an excepetion is thrown during validation. {{Message: Zend_Filter_PregReplace does not have a valid MatchPattern set.}}

class Application_Form_Example extends Zend_Form {

  public function init()
    $price = new Zend_Form_Element_Text('price');
    $price->addFilter('PregReplace', array(
             'match' => array('|,|', '|[^0-9\.]|'), 
             'replace' => array('.', '')

    $this->addElement(new Zend_Form_Element_Submit('submit'));

The test case itself might not be the best approach to format a 'price', but it ilustrate the problem. For the input string {{abc123,456.789}} the expected output should be {{123456.789}}.



No comments to display