Pass value to be used by the INputFilter messageTemplate

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Pass value to be used by the INputFilter messageTemplate

mbn18
Hi,

I need to foreach over array and validate each array value:

So:
        $sanityCheck = new StandardServiceSanityInputFilter();

        foreach ($requests as $request) {
            $sanityCheck->setData($request);
            if (!$sanityCheck->isValid()) {
                $errors[] = $sanityCheck->getMessages();
            }
        }

The problem I couldn't resolve was, how to format the Validator message with additional value which is part of InputFilter context (passed with setData)

Here is one of my tests:

        $this->add(array(
            'name'       => 'simType',
            'required'   => true,
            'validators' => array(
                array(
                    'name' => 'InArray',
                    'options' => array(
                        'haystack' => array('SIM', 'Micro SIM', 'Nano SIM', 'NA'),
                        'strict'   => false,
                    ),
                ),
                array(
                    'name' => 'callback',
                    'options'   => array(
                        'callback'  => array($this, 'simCheck'),
                        'messageVariables' => array (
                            'rowNum'    => '12345', // This is also passed at $inputFilter->setData($array)
                        ),
                        'messages'   => array(
                            'callbackValue'  => "%rowNum% The uploaded file is not an image %value%",
                        ),
                    ),
                ),
            ),
        ));

How can I configure it so %RowNum% will be replaced by the value of 'rowNum' from the InputFilter context?

I can create a new InputFilter per check and pass $rowNum at the constructor but it seems less clean.

Thanks

--------------------------------------------------
Michael Ben-Nes - Linux Web Environment Expert.
http://www.epoch.co.il - LinkedIn
Cellular: +972-54-4848113
--------------------------------------------------