0

I have a custom Zend Validate class extending Zend_Validate_Abstract
The validator is a file validator running an external command line tool that both validates and processes the file.

If the file is invalid, there is no problem. But if the file is valid, can I somehow edit the value of the Zend_Form_Element_File that the validator operates on with some of the information returned from the command line tool?

If not, what would be a good work-around considering I only want to run the external tool once?

Work around idea
I could create a Zend Filter that runs the command line tool, updating the value with parse info, including errors. Then I let the validator simply check if the value array contains the errors left there by the filter?

1 Answer 1

2

Why not pass the element to the validator:

class CustomFileValidator extends Zend_Validate_Abstract {
  public $element = null;

  public function isValid($value) {
        //run external tool
        //check response, validity checks
        //...
        //modify the element if valid. e.g.:
        $this->element->setValue('');
  }

  public setElement(Zend_Form_Element $element) {
      $this->element = $element;
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

That is indeed a possible workaround. Unfortunately I won't have time to try it today, but I will return tomorrow with a follow-up.
I tried it, and it is working nicely. I will use your solution instead of the filter version that I first tried. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.