public function onBeforeFormShow(Oops_Form_Notification $notification) { /** * Attach captcha field */ $notification->attachData('captcha', array('field' => $this->_requestKey, 'required' => true)); }
/** * Performs task * * If $doUpdate is true then tries to store submitted values * Returns definitions of the form structure, errors or detailed success status * * @param array $request * @param bool $doUpdate * @return array Response to be templated */ public function action($request, $doUpdate = false) { /** * Return value * @var array */ $returnValue = array(); /** * Dispatcher should be initialized to this point, but for now let's get sure * @todo consider throw exception if there still no dispatcher */ $this->_initDispatcher(); /** * Collect form specifications * @v ar Oops_Form_Notification */ $beforeShowNotification = $this->_dispatcher->post($this->_onBeforeShowEvent); $returnValue['flagShowForm'] = false; $returnValue['flagUpdate'] = false; $returnValue['flagComplete'] = false; $returnValue['attached'] = $beforeShowNotification->getAttachedData(); if ($beforeShowNotification->isCancelled()) { $returnValue['flagErrors'] = true; $returnValue['flagStatus'] = false; $returnValue['errors'] = $beforeShowNotification->getFormErrors(); return $returnValue; } $returnValue['flagShowForm'] = true; $returnValue['flagErrors'] = false; /** * If there's update flag, try to save the sumbitted values */ if ($doUpdate) { $returnValue['flagUpdate'] = true; /** * Let attached observers check the request * @var Oops_Form_Notification */ $beforeSaveNotification = $this->_dispatcher->post($this->_onBeforeSaveEvent, $request); $returnValue['attached'] = $beforeSaveNotification->getAttachedData($returnValue['attached']); if ($beforeSaveNotification->isCancelled()) { /** * Notification was cancelled, collect errors */ $returnValue['flagStatus'] = false; $returnValue['flagErrors'] = true; $returnValue['errors'] = $beforeSaveNotification->getFormErrors(); } else { /** * If notification was not cancelled store submitted values */ // @todo Let beforeSaveForm observer modify request? $afterSaveNotification = new Oops_Form_Notification($this->_onAfterSaveEvent, $request); // @todo Consider removing this line $afterSaveNotification->attachData('beforeSaveNotification', $beforeSaveNotification); $afterSaveNotification = $this->_dispatcher->postNotification($afterSaveNotification); $returnValue['flagStatus'] = true; $returnValue['attached'] = $afterSaveNotification->getAttachedData($returnValue['attached']); $returnValue['flagShowForm'] = false; $returnValue['flagErrors'] = false; $returnValue['flagComplete'] = true; } } return $returnValue; }