public function add($element) {
        if ((is_object($element) && !is_a($element, 'DScribe\Form\Element')) ||
                (!is_object($element) && !is_array($element)))
            throw new Exception('Form elements must be either an array or an object subclass of DScribe\Form\Element');
        else if (is_array($element)) {
            if (!isset($element['type'])) {
                throw new \Exception('Form elements must of key type');
            }
            $elementClass = 'DScribe\Form\Element\\' . ucfirst($element['type']);
            $element = class_exists($elementClass) ? new $elementClass($element, true, 'values') : new Element($element, true, 'values');
        }
        if ($this->data[$element->name]) {
            $element->data = $this->data[$element->name];
            unset($this->data[$element->name]);
        }

        if (in_array($element->type, array('checkbox', 'radio'))) {
            $this->booleans[$element->name] = $element->name;
        } else if ($element->type === 'fieldset') {
            $this->fieldsets[] = $element->name;
        } else if ($element->type === 'hidden' && $element->name === 'csrf')
            $element->setCsrfKey($this->getName());

        $this->elements[$element->name] = $element;

        if (!$element->filters) {
            $filters = $this->getFilters();
            if ($filters[$element->name])
                $element->filters = $filters[$element->name];
        }

        return $this;
    }
public function add($element) {
        if ((is_object($element) && !is_a($element, 'DScribe\Form\Element')) ||
                (!is_object($element) && !is_array($element)))
            throw new Exception('Form elements must be either an array or an object subclass of DScribe\Form\Element');
        else if (is_array($element)) {
            if (!isset($element['type'])) {
                throw new \Exception('Form elements must of key type');
            }
            $elementClass = 'DScribe\Form\Element\\' . ucfirst($element['type']);
            $element = class_exists($elementClass) ? new $elementClass($element, true, 'values') : new Element($element, true, 'values');
        }
        if ($this->data[$element->name]) {
            $element->data = $this->data[$element->name];
            unset($this->data[$element->name]);
        }

        if (in_array($element->type, array('checkbox', 'radio'))) {
            $this->booleans[$element->name] = $element->name;
        } else if ($element->type === 'fieldset') {
            $this->fieldsets[] = $element->name;
        } else if ($element->type === 'hidden' && $element->name === 'csrf')
            $element->setCsrfKey($this->getName());

        $this->elements[$element->name] = $element;

        if (!$element->filters) {
            $filters = $this->getFilters();
            if ($filters[$element->name])
                $element->filters = $filters[$element->name];
        }

        return $this;
    }
public function add ( $ element ) { if ( ( is_object ( $ element ) && ! is_a ( $ element , 'DScribe\Form\Element' ) ) || ( ! is_object ( $ element ) && ! is_array ( $ element ) ) ) throw new Exception ( 'Form elements must be either an array or an object subclass of DScribe\Form\Element' ) ; else if ( is_array ( $ element ) ) { if ( ! isset ( $ element [ 'type' ] ) ) { throw new \ Exception ( 'Form elements must of key type' ) ; } $ elementClass = 'DScribe\Form\Element\\' . ucfirst ( $ element [ 'type' ] ) ; $ element = class_exists ( $ elementClass ) ? new $ elementClass ( $ element , true , 'values' ) : new Element ( $ element , true , 'values' ) ; } if ( $ this -> data [ $ element -> name ] ) { $ element -> data = $ this -> data [ $ element -> name ] ; unset ( $ this -> data [ $ element -> name ] ) ; } if ( in_array ( $ element -> type , array ( 'checkbox' , 'radio' ) ) ) { $ this -> booleans [ $ element -> name ] = $ element -> name ; } else if ( $ element -> type === 'fieldset' ) { $ this -> fieldsets [ ] = $ element -> name ; } else if ( $ element -> type === 'hidden' && $ element -> name === 'csrf' ) $ element -> setCsrfKey ( $ this -> getName ( ) ) ; $ this -> elements [ $ element -> name ] = $ element ; if ( ! $ element -> filters ) { $ filters = $ this -> getFilters ( ) ; if ( $ filters [ $ element -> name ] ) $ element -> filters = $ filters [ $ element -> name ] ; } return $ this ; }
Adds an element to the fieldset
@param array | \DScribe\Form\Element $element
@return Fieldset
@throws Exception
Adds an element to the fieldset