/** * Adds a form element to the class * * The type and value parameters are optional, though it is a timesaver. * See setType for the form types. * See setValue for value information. * * @author Matthew McNaney <mcnaney at gmail dot com> * @param string name The name of the form element * @param string type The type of form element (text, check, radio, etc) * @param mixed value The default value of the form element */ public function add($name, $type = null, $value = null) { if (preg_match('/[^\\[\\]\\w]+/i', $name)) { return PHPWS_Error::get(PHPWS_FORM_BAD_NAME, 'core', 'PHPWS_Form::add', array($name)); } $result = PHPWS_Form::createElement($name, $type, $value); if (PHPWS_Error::isError($result)) { return $result; } if (is_array($result)) { foreach ($result as $element) { if ($type != 'radio') { $element->isArray = true; } $element->_form = $this; $this->_elements[$name][$element->value] = $element; $this->_elements[$name][$element->value]->key = $element->value; $this->_elements[$name][$element->value]->setId(); } } else { if (isset($this->_elements[$name])) { $this->_elements[$name][0]->isArray = true; $result->isArray = true; } $result->_form = $this; $this->_elements[$name][] = $result; $current_key = $this->getKey($name); $this->_elements[$name][$current_key]->key = $current_key; $this->_elements[$name][$current_key]->setId(); } $this->types[$name] = $type; return true; }