Exemplo n.º 1
0
 private static function validateVars($context, GWF_Form $form, $validator)
 {
     $errors = array();
     $method = $form->getMethod();
     foreach ($form->getFormData() as $key => $data) {
         # Skippers
         if (in_array($data[0], self::$SKIPPERS, true) || $data[0] === GWF_Form::SUBMITS || $data[0] === GWF_Form::SUBMIT_IMGS) {
             continue;
         }
         # Captcha
         if ($data[0] === GWF_Form::CAPTCHA) {
             if (false !== ($error = self::validateCaptcha($context, $form, $validator, $key))) {
                 $errors[] = $error;
             }
             continue;
         }
         # Get forms do not validate mo/me
         if ($method === GWF_Form::METHOD_GET) {
             if ($key === 'mo' || $key === 'me') {
                 continue;
             }
         }
         # Validators
         $func_name = 'validate_' . Common::substrUntil($key, '[', $key);
         $function = array($validator, $func_name);
         if (!method_exists($validator, $func_name)) {
             $errors[] = GWF_HTML::lang('ERR_METHOD_MISSING', array($func_name, get_class($validator)));
         } elseif (false !== ($error = call_user_func($function, $context, $form->getVar($key)))) {
             $errors[] = $error;
         }
     }
     return count($errors) === 0 ? false : $errors;
 }
Exemplo n.º 2
0
 /**
  * Return all values from the form except buttons.
  * @param GWF_Form $form
  * @return array
  */
 public static function getFormVars(GWF_Form $form)
 {
     $back = array();
     foreach ($form->getFormData() as $key => $d) {
         switch ($d[0]) {
             case GWF_Form::HIDDEN:
             case GWF_Form::SUBMIT:
             case GWF_Form::SUBMITS:
             case GWF_Form::SUBMIT_IMG:
             case GWF_Form::SUBMIT_IMGS:
                 break;
             default:
                 $back[$key] = $form->getVar($key, '');
         }
     }
     return $back;
 }