addPrefixPath('Qs_Captcha', 'Qs/Captcha', Qs_Form_Element_Captcha::CAPTCHA); parent::__construct($spec, $options); } public function isValid($value, $context = null) { if ($this->isRequired()) { $notEmpty = new Qs_Validate_NotEmpty(); if (!$notEmpty->isValid($value['input'])) { $this->_messages = array_merge($this->_messages, $notEmpty->getMessages()); $this->_errors = array_merge($this->_errors, $notEmpty->getErrors()); return false; } } return parent::isValid($value, $context); } public function loadDefaultDecorators() { if ($this->loadDefaultDecoratorsIsDisabled()) { return $this; } $decorators = $this->getDecorators(); if (empty($decorators)) { $this->addDecorator('Errors') ->addDecorator('Description', ['tag' => 'p', 'class' => 'description']) ->addDecorator('HtmlTag', ['tag' => 'dd', 'id' => $this->getName() . '-element']) ->addDecorator('Label', ['tag' => 'dt']); } return $this; } /** * @return Qs_Captcha_Image|Zend_Captcha_Adapter */ public function getCaptcha() { if (null === $this->_captcha) { $this->setCaptcha('image'); } return $this->_captcha; } public function initRender() { if ($this->_initialized) { return $this; } $captcha = $this->getCaptcha(); $captcha->setName($this->getFullyQualifiedName()); $decorators = $this->getDecorators(); $decorator = $captcha->getDecorator(); if (!empty($decorator)) { array_unshift($decorators, $decorator); } $decorator = ['Captcha', ['captcha' => $captcha]]; array_unshift($decorators, $decorator); $this->setDecorators($decorators); $this->setValue($this->getCaptcha()->generate()); $this->_initialized = true; return $this; } public function render(Zend_View_Interface $view = null) { $this->initRender(); return Zend_Form_Element_Xhtml::render($view); } }