Exemplo n.º 1
0
 public static function validate()
 {
     $data = file_get_contents(Application::host() . 'ext/hn_captcha/hn_captcha.x1.example.php?hncaptcha=' . Application::param('hncaptcha') . '&public_key=' . Application::param('public_key') . '&private_key=' . Application::param('private_key'));
     if (strpos($data, 'Congratulation') !== FALSE) {
         $ret = true;
     } else {
         FormErrors::add('captcha', 'Invalid captcha entry, please try again');
         $ret = false;
     }
     return $ret;
 }
 protected function setupDisplay($disp)
 {
     $disp->setValue('form_errors', FormErrors::all());
     $disp->setValue('handler', $this->getClass());
     $disp->setValue('state', $this->state);
     $disp->addView('system_setup', 'pilot.views.PilotSetupMain');
     if ($this->state == 'main') {
         if (is_object($this->user_to_edit)) {
             $disp->setValue('user_id', $this->user_to_edit->id());
         }
         $access_form = $this->accessForm($this->access_to_edit);
         $group_form = $this->groupForm($this->group_to_edit);
         $user_form = $this->userForm($this->user_to_edit);
         $sf_form = $this->siteFunctionForm($this->site_function_to_edit);
         $disp->addForm($access_form);
         $disp->addForm($group_form);
         $disp->addForm($user_form);
         $disp->addForm($sf_form);
         if ($this->saved || $this->cancel_edit) {
             if ($this->saved) {
                 $disp->setValue('saved', $this->saved);
             }
             $access_form->clear();
             $group_form->clear();
             $user_form->clear();
             $sf_form->clear();
         } else {
             if ($this->failed) {
                 $disp->setValue('failed', $this->failed);
             }
         }
     } else {
         if ($this->state == 'change_user_password' && $this->user_to_edit) {
             $form = Form::load('pilot.views.UserPassword');
             $form->setInputValues($this->user_to_edit);
             $disp->addForm($form);
             $disp->setValue('user_name', $this->user_to_edit->toString());
         } else {
             $disp->setValue('delete_class', $this->delete_class);
             $disp->setValue('delete_label', $this->delete_label);
             $disp->setValue('delete_command', $this->delete_command);
             if ($this->state == 'choose_delete') {
                 $form = Form::load('pilot.views.ChooseObjects');
                 $form->setOptions('objects', $this->objects_to_choose);
                 $form->setInputValue('delete_state', 'confirm');
             } else {
                 if ($this->state == 'confirm_delete') {
                     $form = Form::load('pilot.views.ConfirmObjects');
                     $form->setOptions('objects', $this->objects_to_delete);
                     $form->setInputValue('delete_state', 'delete');
                 } else {
                     if ($this->state == 'delete') {
                         $form = Form::load('pilot.views.DeleteObjects');
                         $form->setOptions('objects', $this->objects_to_delete);
                     } else {
                         throw new Exception('The PilotSetup Handler is in an unknown state: ' . $this->state);
                     }
                 }
             }
             $disp->addForm($form);
         }
     }
 }
 /**
  * Get an error message for a form element
  * @param name - the form element to get an error message for
  * @return string - the error message if one exists
  * @access public
  * @static 
  */
 public static function message($name)
 {
     if (isset(FormErrors::current()->errors[$name])) {
         $ret = FormErrors::current()->errors[$name];
     } else {
         $ret = '';
     }
     return $ret;
 }
Exemplo n.º 4
0
 public function formError($name)
 {
     return FormErrors::current()->message($name);
 }
 function validate($value)
 {
     $ret = true;
     switch ($this->type) {
         case 'REQUIRED':
             if ($value || is_numeric($value)) {
                 $ret = true;
             } else {
                 $ret = false;
             }
             break;
         case 'NOT':
             if ($value) {
                 $match = preg_replace('/\\\\/', '\\\\', $this->value);
                 $ret = !preg_match('/' . $match . '/', $value);
             }
             break;
         case 'MATCH':
             if ($value) {
                 $match = preg_replace('/\\\\/', '\\\\', $this->value);
                 $ret = preg_match('/' . $match . '/', $value);
             }
             break;
         case 'GREATER':
             if ($value) {
                 if (is_numeric($value)) {
                     $ret = $value > $this->value;
                 } else {
                     $ret = false;
                 }
             } else {
                 $ret = false;
             }
             break;
         case 'LESS':
             if ($value) {
                 if (is_numeric($value)) {
                     $ret = $value < $this->value;
                 } else {
                     $ret = false;
                 }
             }
             break;
         case 'EQUALS':
             if ($value) {
                 if (is_numeric($value)) {
                     $ret = $value == $this->value;
                 } else {
                     $ret = false;
                 }
             }
             break;
         case 'NOT_EQUALS':
             if ($value) {
                 if (is_numeric($value)) {
                     $ret = $value != $this->value;
                 } else {
                     $ret = false;
                 }
             }
             break;
         case 'NUMBER':
             $ret = is_numeric($value);
             break;
         case 'EMAIL':
             if ($value) {
                 $ret = FormValidationRequirement::validateEmail($value);
             }
             break;
         case 'PASSWORD':
             if ($value) {
                 $confirm = Application::param($this->name . '_confirm');
                 $ret = $value == $confirm;
             }
             break;
         case 'DATE':
             if ($value) {
                 $ret = true;
             } else {
                 $ret = false;
             }
             break;
         case 'CUSTOM':
             $class = $this->value;
             $obj = new $class();
             $ret = $obj->validate($value);
             if (!$ret) {
                 $this->error_message = $obj->errorMessage();
             }
             break;
         default:
             throw new Exception('Unsupported validation type: ' . $this->type . ' passed to validate in FormValidationRequirement');
             break;
     }
     if (!$ret) {
         FormErrors::add($this->name, $this->error_message);
     }
     return $ret;
 }
Exemplo n.º 6
0
 private function checkField($name, $Field)
 {
     if ($Field instanceof FormField) {
         $Field->setName($name);
         if (!$Field->hasId()) {
             $Field->setId($name);
         }
         $Field->check();
         return true;
     } else {
         FormErrors::badFieldFormat($name);
     }
     return false;
 }