Exemplo n.º 1
0
 public function onBeforeFormSave(Oops_Form_Notification $notification)
 {
     $request = $notification->getInfo();
     $passedValue = strval($request[$this->_requestKey]);
     if (strlen($passedValue)) {
         require_once 'Oops/Kcaptcha/Storage.php';
         $captchaStorage = new Oops_Kcaptcha_Storage();
         /**
          * Here we could pass second argument to captcha checker in irder to keep value in storage
          * If so we could skip showing captcha on other form form errors
          */
         if ($captchaStorage->Check($this->_requestKey)) {
             return;
         }
     }
     $notification->Cancel("Captcha error", $this->_requestKey);
 }
Exemplo n.º 2
0
 /**
  * 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;
 }