Пример #1
0
 /**
  *
  * Validates the form input to make sure that it is valid.  This extends the 
  * standard QuickForm method by adding custom validation from the Record object.
  *
  */
 function validate()
 {
     $this->_build();
     //$this->push();
     if ($this->isSubmitted()) {
         $app =& Dataface_Application::getInstance();
         $res = $app->fireEvent('Dataface_QuickForm_before_validate');
         if (PEAR::isError($res)) {
             //echo "Failed";exit;
             $this->_errors[] = $res->getMessage();
         }
         /*
          *
          * We only need to validate if the form was submitted.
          *
          */
         //foreach ( array_keys($this->_fields) as $field ){
         $rec = new Dataface_Record($this->_record->_table->tablename, $this->getSubmitValues());
         $rec->pouch = $this->_record->pouch;
         foreach ($this->_fieldnames as $field) {
             /*
              *
              * Go through each field (corresponding to a record field) in the form
              * and validate against the record's validation script.
              *
              */
             $el =& $this->getElementByFieldName($field);
             if (PEAR::isError($el)) {
                 unset($el);
                 continue;
             }
             $params = array('message' => df_translate('scripts.GLOBAL.MESSAGE.PERMISSION_DENIED', "Permission Denied"));
             // default error message to be displayed beside the field.
             $res = $rec->validate($field, $el->getValue(), $params);
             if (!$res) {
                 /*
                  *
                  * The default validate() method checks to see if the form validates based
                  * on the size of the _errors array.  (If it has count = 0, then it validates.
                  * Adding an error to this array will cause the parent's validate method to return
                  * false.
                  *
                  */
                 $this->_errors[$el->getName()] = $params['message'];
             }
             unset($params);
         }
     }
     /*
      *
      * Now that we have done our work, we can let the default validate method do the rest
      * of the work.
      *
      */
     return parent::validate();
 }