Is there a Zend filter similar to Zend Validator Identical?

Is there a Zend filter similar to the Zend Validator ID?

In the case when I have to filter the input == 'test'

$el->addFilter('Identical','test');

The problem is that such a filter does not exist.

Thank you yosef

+3
source share
3 answers

I am not sure how this filter should work, because it is not clear from your question. In any case, I created a special filter that will check whether the value of the input file matches some $ token. If they are equal, then the input value will be an empty string.

The filter is as follows:

// file: APPLICATION_PATH/filters/Identical.php 

class My_Filter_Identical implements Zend_Filter_Interface {

    /**
     * Token with witch input is compared
     *
     * @var string
     */
    protected $_token;

    /**
     * Set token
     *
     * @param  string
     * @return void
     */
    public function __construct($token = '') {
        $this->_token = $token;
    }

    /**
     * Filtering method 
     *
     * @param string $value value of input filed
     * @return string
     */
    public function filter($value) {

        if ($value !== $this->_token) {
            return $value;
        }

        return '';
    }

}

To apply it to a given form element:

require_once (APPLICATION_PATH . '/filters/Identical.php');
$el1->addFilter(new My_Filter_Identical('test'));

require_once , , .

:

pregReplace. , , pregReplace:

$el1->addFilter('pregReplace',array('/test/',''));

, , , , . , , .

+4

- , test? ? , , el, test?

, Zend_Filter_PregReplace

$filter = new Zend_Filter_PregReplace(array('match' => '/test/', 'replace' => ''));
$input  = 'What is this test about!';
$filter->filter($input);

What is this about!

, , , . .

+1

It is not clear what you are trying to do. If you give more explanation, that would be good.

I need to remove all input, so regex is not recommended.

If you just want to clear the data in the form elements, you can use one of the following values:

  • Remove the element value by setting the element value to value.

    $ el-> SetValue (zero);

  • or reset all form elements

    $ form → reset ();

+1
source

Source: https://habr.com/ru/post/1788369/


All Articles