Skip to content
Snippets Groups Projects
class.forms.php 128 KiB
Newer Older
  • Learn to ignore specific revisions
  • Peter Rotich's avatar
    Peter Rotich committed
            $this->setFields($fields);
    
            return $this->fields;
        }
    
        function isValid() {
    
            if (!parent::isValid())
                return false;
    
            // Do additional validations
            if (!($dept = $this->getDept()))
                $this->getField('dept')->addError(
                        __('Unknown department'));
    
            return !$this->errors();
        }
    
        function render($options) {
    
            switch(strtolower($options['template'])) {
            case 'simple':
                $inc = STAFFINC_DIR . 'templates/dynamic-form-simple.tmpl.php';
                break;
            default:
                throw new Exception(sprintf(__('%s: Unknown template style %s'),
                            get_class(), $options['template']));
            }
    
            $form = $this;
            include $inc;
    
        }
    
        function getDept() {
    
            if (!isset($this->_dept)) {
                if (($id = $this->getField('dept')->getClean()))
                    $this->_dept = Dept::lookup($id);
            }
    
            return $this->_dept;
        }
    }
    
    
    /**
     * FieldUnchanged
     *
     * Thrown in the to_database() method to indicate the value should not be
     * saved in the database (it wasn't changed in the request)
     */
    class FieldUnchanged extends Exception {}