setOption('blockData', $blockData); $this->_initAction(); if ('insert' == $this->_action) { $this->exec(); return []; } else { $form = $this->_getNewForm(); $form->setDefaults(); return $this->getFormItem($form); } } protected function _doInsertAjax() { if ($this->isSideBlock()) { $this->insertAjaxSideBlock(); return; } parent::_doInsertAjax(); } protected function insertAjaxSideBlock() { $form = $this->_getNewForm(); $result = $form->validateAjax(); if ($result['isValid']) { $this->_initFromForm($form); if (false === $this->_getDataObj()->insert()) { $result['idValid'] = false; $result['formErrors'] = $this->_getDataObj()->getErrors(); } else { $this->_postInsert(); } } $this->_displayJson($result); } protected function _postInsert() { $data = $this->_getDataObj()->clearData()->getData(); $this->_sendNotifications($data); $this->_log(); if (!$this->isSideBlock()) { $this->redirect($this->url() . '/thanks.html'); } return $this; } protected function _sendNotifications($data) { $this->_sendAdminNotification($data); return $this; } protected function _getFormOptions($type = null) { $options = parent::_getFormOptions($type); $options['isSideBlock'] = $this->isSideBlock(); return $options; } protected function isSideBlock() { return (bool) $this->getOption('blockData'); } protected function getFormItem(Qs_Form $form) { $item = [ 'tpl' => 'Form/sideBlockForm.tpl', 'formId' => $form->getId(), 'text' => $form->render(), ]; if (($item['isSideBlock'] = $this->isSideBlock())) { $item['thankYouMessage'] = $this->getOption('blockData[thanksMessage]'); } else { $item['header'] = $this->getConfig('formHeader'); } return $item; } protected function _addFormItem(Qs_Form $form) { $this->_addItem($this->getFormItem($form)); return $this; } }