addElement( 'text', 'query', ['label' => 'Search', 'size' => 50, 'filters' => [new Zend_Filter_StringTrim()]] ); $this->_setQueryDescription(); return $this; } public function setOptions(array $options) { if (isset($options['filterFields'])) { $this->_filterFields = $options['filterFields']; unset($options['filterFields']); } if (isset($options['filterQueryDescriptionFormat'])) { $this->_filterQueryDescriptionFormat = $options['filterQueryDescriptionFormat']; unset($options['filterQueryDescriptionFormat']); } if (isset($options['descriptionPlaceholder'])) { $this->_descriptionPlaceholder = $options['descriptionPlaceholder']; unset($options['descriptionPlaceholder']); } return parent::setOptions($options); } protected function _setQueryDescription() { if (!empty($this->_filterFields)) { $description = $this->_filterQueryDescriptionFormat; if (false !== strpos($description, $this->_descriptionPlaceholder)) { $fields = '"' . Qs_Array::implodeLast('", "', '" or "', $this->_filterFields) . '"'; $description = str_replace($this->_descriptionPlaceholder, $fields, $this->_filterQueryDescriptionFormat); } $this->getElement('query')->setDescription($description); } return $this; } public function addSearchButton() { return $this->addElement('submit', 'btnSearch', [ 'label' => 'Search', 'ignore' => true, 'class' => 'btn btn-primary', ]); } public function addResetButton() { $this->addElement( 'submit', 'btnReset', [ 'label' => 'Reset', 'ignore' => true, 'attribs' => [ 'class' => 'btn btn-light', 'onclick' => "document.location='" . constant('BASE_URL') . '/' . constant('CURRENT_PAGE') . "';", 'helper' => 'formInputButton', ], ] ); return $this; } public function addButtons() { $this->addSearchButton(); $this->addResetButton(); $this->addDisplayGroup(['btnSearch', 'btnReset'], 'submitGroup'); return $this; } public function isSubmitted() { $method = $this->getMethod(); if (0 == strcasecmp($_SERVER['REQUEST_METHOD'], $method)) { $formData = ($method == 'get') ? $_GET : $_POST; if (array_key_exists('__idItem', $this->_elements)) { if ($this->getElement('__idItem')->getValue() == Qs_Array::get($formData, '__idItem')) { return true; } } else { /** @var Zend_Form_Element $element */ foreach ($this->_elements as $element) { if (array_key_exists($element->getName(), $formData)) { return true; } } } } return false; } }