addElement( 'select', 'idProduct', array( 'label' => 'Product', 'required' => true, 'multiOptions' => array('' => 'Select Product') + (array)$this->dataObj->getProduct4Select(array('id', 'name')) ) ); $form->getElement('idProduct')->removeDecorator('Label'); $form->addElement('text', 'name', array('label' => 'Your Name', 'required' => true)); $form->getElement('name')->removeDecorator('Label'); $form->addElement('emailOrPhone', 'emailOrPhone', array('label' => 'Your Email or Phone Number', 'required' => true)); $form->getElement('emailOrPhone')->removeDecorator('Label'); $form->addElement('textarea', 'comments', array('label' => 'Comments', 'required' => true, 'rows' => 10)); $form->getElement('comments')->removeDecorator('Label'); $form->addElement('captcha', 'captcha'); $form->getElement('captcha')->removeDecorator('Label'); $form->prependId(); return $this; } protected function _initFromForm(Qs_Form $form) { $data = $form->getValues(); $data['product'] = $this->dataObj->tableProduct->search($data['idProduct'], 'name'); $this->dataObj->initFromForm($data); return $this; } protected function _bindFormButtons(Qs_Form $form) { $form->addElement('submit', 'btnSubmit', array( 'label' => 'Submit', 'attribs' => array('class' => 'btn'), 'decorators' => array('ViewHelper') ) ); $decorators = array('FormElements'); $decorators[] = array('decorator' => 'HtmlTag', 'options' => array('tag' => 'div')); $decorators[] = 'DtDdWrapper'; $form->addDisplayGroup(array('btnSubmit'), 'submitGroup', array('decorators' => $decorators)); return $this; } protected function _getMailData(array $data) { $mailData = array( 'name' => htmlspecialchars($data['name']), 'emailOrPhone' => htmlspecialchars($data['emailOrPhone']), 'product' => htmlspecialchars($data['product']), 'comments' => nl2br(htmlspecialchars($data['comments'])), 'link' => BASE_URL . '/' . Qs_SiteMap::findFirst(null, array('type' => 'Form_PurchasingProduct_Admin'), null, 'fullAlias') . '?action=view&id=' . $data['id'], ); return $mailData; } protected function _renderForm(Qs_Form $form, $template = null, $item = array()) { $this->doc->assign('_appThankYouContact', $this->getShowThankYou()); if (null !== $template && false !== ($item['tpl'] = $this->getTemplate($template, false))) { $form->initRender(); $form->removeContainers(); $item['form'] = $form; } else { $item['tpl'] = $this->getTemplate('text.tpl'); $item['text'] = $form->render(); } $this->_addItem($item); return true; } protected function _postInsert() { $data = $this->dataObj->clearData()->getData(); $this->_sendAdminNotification($data); $this->setShowThankYou(); return $this; } public function setShowThankYou() { $session = $this->_getSession(); $session->{self::SESSION_NAME} = true; $session->setExpirationHops(1, self::SESSION_NAME); return $this; } /** * Return session object * * @return Qs_Session_Namespace */ protected function _getSession() { if (null === $this->_session) { $this->_session = new Qs_Session_Namespace(get_class($this), true); } return $this->_session; } public function getShowThankYou() { $session = $this->_getSession(); return (bool) $session->{self::SESSION_NAME}; } protected function _setBackMessage($msg = null) { return true; } /** * Return new form object * * @return Qs_From */ protected function _getNewForm() { $this->doc->addScript('js/defaultHint.js', array(), 'defaultHint'); $params = array( 'elements' => array( array('selector' => '#form_purchasingproduct-form-name', 'hint' => 'Your Name'), array('selector' => '#form_purchasingproduct-form-emailOrPhone', 'hint' => 'Your Email or Phone #'), array('selector' => '#form_purchasingproduct-form-comments', 'hint' => 'Message') ) ); $this->doc->addInitFunction ('$().defaultHint', array($params)); $form = parent::_getNewForm(); $form->action->setValue('insertPurchasing'); return $form; } protected function _doNewBlock() { $form = $this->_getNewForm(); $form->setDefaults($this->getFormDefaults()); return $form; } protected function _doInsertPurchasing() { return $this->_doInsert(); } protected function _doInsertPurchasingAjax() { $this->_doInsertAjax(); } protected function _doInsertPurchasingAjaxBlock() { $this->_doInsertAjax(); } protected function _doInsertPurchasingBlock() { $form = $this->_getNewForm(); if ($form->validate()) { $this->_initFromForm($form); if (($e = $this->dataObj->insert()) instanceof Exception) { if ($e instanceof Qs_Db_Obj_Exception) { $this->_setBackError($e->getMessage()); } else { Qs_Debug::processException($e); } } else { $this->_postInsert(); $this->_setBackMessage(Qs_ViewController::MSG_ADDED); } $this->_doBack(); } else { return $form; } return false; } }