Validation function takes two argument: id for which it is called and array of fields' values (usually values for entire formset, as defined in forms.inc.php). The function must always return an array with an error (or error array) assigned to a form element (formset name or field path). Even if there are no errors, key must be set with an empty value. Validation functions are assigned in $cfg_db['_validators'] (config.values.php).
Пример #1
0
 /**
  * Outputs HTML for the forms under the menu tab
  *
  * @param bool  $show_restore_default whether to show "restore default"
  *                                    button besides the input field
  * @param array &$js_default          stores JavaScript code
  *                                    to be displayed
  * @param array &$js                  will be updated with javascript code
  * @param bool  $show_buttons         whether show submit and reset button
  *
  * @return string $htmlOutput
  */
 private function _displayForms($show_restore_default, array &$js_default, array &$js, $show_buttons)
 {
     $htmlOutput = '';
     $validators = Validator::getValidators($this->_configFile);
     foreach ($this->_forms as $form) {
         /* @var $form Form */
         $form_desc = isset($GLOBALS["strConfigForm_{$form->name}_desc"]) ? PMA_lang("Form_{$form->name}_desc") : '';
         $form_errors = isset($this->_errors[$form->name]) ? $this->_errors[$form->name] : null;
         $htmlOutput .= PMA_displayFieldsetTop(PMA_lang("Form_{$form->name}"), $form_desc, $form_errors, array('id' => $form->name));
         foreach ($form->fields as $field => $path) {
             $work_path = array_search($path, $this->_systemPaths);
             $translated_path = $this->_translatedPaths[$work_path];
             // always true/false for user preferences display
             // otherwise null
             $userprefs_allow = isset($this->_userprefsKeys[$path]) ? !isset($this->_userprefsDisallow[$path]) : null;
             // display input
             $htmlOutput .= $this->_displayFieldInput($form, $field, $path, $work_path, $translated_path, $show_restore_default, $userprefs_allow, $js_default);
             // register JS validators for this field
             if (isset($validators[$path])) {
                 PMA_addJsValidate($translated_path, $validators[$path], $js);
             }
         }
         $htmlOutput .= PMA_displayFieldsetBottom($show_buttons);
     }
     return $htmlOutput;
 }