Esempio n. 1
0
 static function checkFiles($formid_name, $rules, $messages = array())
 {
     if (empty($rules) || empty($rules[$formid_name])) {
         return;
     }
     $rules = $rules[$formid_name];
     if (isset($messages[$formid_name])) {
         POSTErrors::setCustomMessages($messages[$formid_name]);
     }
     foreach ($rules as $name => $cr) {
         foreach ($cr as $rule => $rule_value) {
             if ($rule === 'required' && $rule_value === 'true' && !t(new UploadedFiles($name))->isUploaded($name)) {
                 POSTErrors::addError($name, $add_id, Language::message('checkers', 'REQUIRED'));
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * Process incoming POST data. 
  * This happens only if current request method is POST and it not empty.
  *
  * It consists of sequence of checks and calls:
  *
  * <ol>
  * <li>"BeforeHandlePOST" event is called with $this parameter.</li>
  * <li>It decides whenever form should be checked upon trusted signatures.</li>
  * <li>If the form should be checked, "BeforeCheckSignature" event is called with
  * $this parameter.</li>
  * <li>Checks incoming form signature to detect POST data from the form, that user didn't visit.</li>
  * <li>"BeforeCheckByRules" event is called with $post as a first parameter and real 
  * complete form signature value, that has been passed by the client's UA.
  * <li>Checks incoming form data with pointed value checkers. And if error occurred, 
  * it shows error message. No data will be passed to declared data handlers.</li>
  * <li>"BeforeCallHandlers" event is called with $this and $formid (just id, no signature field).</li>
  * <li>All registered checkers are called to perform form data checks in userland.
  * If CheckerException is raised, error message will be shown without calling declared 
  * handlers.</li>
  * <li>Declared data handlers and finalizers are called.</li>
  * <li>"AfterHandlePOST" event is called with $this parameter and $ret string, which points
  * where to redirect after data processing.</li>
  *
  * @param null
  * @return null
  * @see DataHandlerObject
  * @see PageHandlerObject
  */
 protected function handlePOST()
 {
     $this->trigger("BeforeHandlePOST", $this);
     if ($this->post->isEmpty()) {
         Header::redirect(requestURI(true), Header::SEE_OTHER);
     }
     WidgetLoader::load("WForm");
     list($formid) = explode(":", $this->post->{WForm::signature_name});
     if (empty($formid)) {
         Header::redirect(requestURI(true), Header::SEE_OTHER);
     }
     if (!in_array($formid, $this->no_check_forms)) {
         $this->trigger("BeforeCheckSignature", $this);
         if (!$this->checkSignature($this->post->{WForm::signature_name})) {
             Header::redirect(requestURI(true), Header::SEE_OTHER);
         }
         POSTErrors::flushErrors();
         $this->trigger("BeforeCheckByRules", array(&$this->post, $this->post->{WForm::signature_name}));
         POSTChecker::checkByRules($this->post->{WForm::signature_name}, $this->checker_rules, $this->checker_messages);
         POSTChecker::checkFiles($this->post->{WForm::signature_name}, $this->file_rules, $this->checker_messages);
         if (POSTErrors::hasErrors()) {
             POSTErrors::saveErrorList();
             Header::redirect(requestURI(true), Header::SEE_OTHER);
         }
         //DataUpdaterPool::restorePool();
     }
     $this->trigger("BeforeCallHandlers", array($this, &$formid));
     try {
         DataUpdaterPool::callCheckers($formid);
     } catch (CheckerException $e) {
         POSTErrors::addError($e->getWidgetName(), $e->getAdditionalId(), $e->getMessage());
     }
     if (POSTErrors::hasErrors()) {
         POSTErrors::saveErrorList();
         Header::redirect(requestURI(true), Header::SEE_OTHER);
     }
     DataUpdaterPool::callHandlers($formid);
     DataUpdaterPool::callFinalize($formid);
     $ret = null;
     if (isset($this->pagehandler)) {
         $ret = $this->pagehandler->handle();
     }
     $this->trigger("AfterHandlePOST", array($this, &$ret));
     if (is_numeric($ret)) {
         $this->gotoLocation($this->navigator->getStepURL($ret));
     } elseif (is_string($ret)) {
         $this->gotoLocation($ret);
     }
     //$this->gotoStep_0();
     Header::redirect(requestURI(true), Header::SEE_OTHER);
     exit;
 }