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')); } } } }
/** * Method description * * More detailed method description * @param mixed $post * @param array $errors * @return string */ function restorePOST() { $errors = POSTErrors::getErrorFor($this->getName(), $this->getAdditionalID()); if ($errors !== null) { $this->setFilterError(implode("<br/>", $errors)); } $post_data = POSTErrors::getPOSTData($this->getName(), $this->getAdditionalID()); if (isset($post_data)) { ResultSetPool::set(t(new ResultSet())->f1("wselect[name=" . $this->getName() . "] wselectoption[value=" . $post_data . "]")->set('selected', 1), ResultSetPool::SYSTEM_PRIORITY); } }
/** * Resets array of errors and appropriate data. * Additionally persistent storage will be cleaned * too. * * @param null * @return null */ static function flushErrors() { $storage = Storage::createWithSession("post_errors"); $storage->un_set('errors'); $storage->un_set('data'); self::$errors = array(); self::$post_data = array(); }
/** * Method description * * More detailed method description * @param mixed $post * @param array $errors * @return string */ function restorePOST() { $errors = POSTErrors::getErrorFor($this->getName(), $this->getAdditionalID()); if ($errors !== null) { $this->setFilterError(implode("<br/>", $errors)); } $post_data = POSTErrors::getPOSTData($this->getName(), $this->getAdditionalID()); if (isset($post_data)) { $this->setChecked(1); } }
/** * Method description * * More detailed method description * @param mixed $post * @param array $errors * @return string */ function restorePOST() { $errors = POSTErrors::getErrorFor($this->getName(), $this->getAdditionalID()); if ($errors !== null) { $this->setFilterError(implode("<br/>", $errors)); } $this->setValue(POSTErrors::getPOSTData($this->getName(), $this->getAdditionalID())); }
/** * Handles POST data while AJAX request. * It works like {Controller::handlePOST} and signaatures will be checked unless * form is on the current page and <code>no_check</code> attribute is not specified. * * Typical use-case of this function is posting form with javascript with * <code>$(form).serialize()</code> method or <code>ajaxSubmit</code> from * jquert.form plugin. * * Instead of redirects, like in <code>Controller::handlePOST()</code> * method, <code>exit()</code> calls will be used. * * Another difference is that no "save form values and show error boxes" sequence * is used. If some checker of validator error are present, <code>exit()</code> * will terminate futher form processing. * * Additionally, unlike <code>Controller::handlePOST</code>, handler methods could specify * <code>responce_string</code> to return status of form processing. It will be echo'ed at once. * * @param null * @return null */ protected function handlePOST() { $this->trigger("BeforeHandlePOST", $this); if ($this->post->isEmpty()) { Header::redirect(requestURI(true), Header::SEE_OTHER); } $formid = null; WidgetLoader::load("WForm"); list($formid) = explode(":", $this->post->{WForm::signature_name}); if (!empty($formid) && !in_array($formid, $this->no_check_forms)) { $this->trigger("BeforeCheckSignature", $this); if (!$this->checkSignature($this->post->{WForm::signature_name})) { exit("Error while checking POST data 1"); } 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()) { //Header::redirect(requestURI(true), Header::SEE_OTHER); exit("Error while checking POST data 2"); } $this->trigger("BeforeCallHandlers", array($this, &$formid)); try { DataUpdaterPool::callCheckers($formid); } catch (CheckerException $e) { exit("Error " . $e->getMessage() . " in widget " . $e->getWidgetName); } DataUpdaterPool::callHandlers($formid); DataUpdaterPool::callFinalize($formid); } else { try { DataUpdaterPool::callCheckers($formid); } catch (CheckerException $e) { exit("Error " . $e->getMessage() . " in widget " . $e->getWidgetName); } DataUpdaterPool::callHandlers($formid); DataUpdaterPool::callFinalize($formid); } $this->trigger("AfterHandlePOST", $this); if (isset($this->response_string)) { $this->trigger("AfterHeadBodyTailResponce", array($this, &$this->response_string)); echo $this->response_string; } }