/** * * Adds DB_Table columns to a pre-existing HTML_QuickForm object. * * @author Ian Eure <*****@*****.**> * * @static * * @access public * * @param object &$form An HTML_QuickForm object. * * @param array $cols A sequential array of DB_Table column definitions * from which to create form elements. * * @param string $arrayName By default, the form will use the names * of the columns as the names of the form elements. If you pass * $arrayName, the column names will become keys in an array named * for this parameter. * * @return void * */ function addElements(&$form, $cols, $arrayName = null) { $elements =& DB_Table_QuickForm::getElements($cols, $arrayName); $cols_keys = array_keys($cols); foreach (array_keys($elements) as $k) { $element =& $elements[$k]; // are we adding a group? if (is_array($element)) { // get the label for the group. have to do it this way // because the group of elements does not itself have a // label, there are only the labels for the individual // elements. $tmp = $cols[$cols_keys[$k]]; if (!isset($tmp['qf_label'])) { $label = $cols_keys[$k]; if ($arrayName) { $label = $arrayName . "[{$label}]"; } } else { $label = $tmp['qf_label']; } // set the element name if ($arrayName) { $name = $arrayName . '[' . $cols_keys[$k] . ']'; } else { $name = $cols_keys[$k]; } // fix the column definition temporarily to get the separator // for the group $col = $cols[$cols_keys[$k]]; DB_Table_QuickForm::fixColDef($col, $name); // done $group =& $form->addGroup($element, $name, $label, $col['qf_groupsep']); // set default value (if given) for radio elements // (reason: QF "resets" the checked state, when adding a group) if ($tmp['qf_type'] == 'radio' && isset($tmp['qf_setvalue'])) { $form->setDefaults(array($name => $tmp['qf_setvalue'])); } } elseif (is_object($element)) { $form->addElement($element); } } }
/** * * Creates and returns an array of QuickForm elements based on a DB_Table * column name. * * @author Ian Eure <*****@*****.**> * * @access public * * @param string $cols Array of DB_Table column names * * @param string $array_name The name to use for the generated QuickForm * elements. * * @return object HTML_QuickForm_Element * * @see HTML_QuickForm * * @see DB_Table_QuickForm * */ function &getFormElements($cols, $array_name = null) { include_once 'DB/Table/QuickForm.php'; $elements =& DB_Table_QuickForm::getElements($cols, $array_name); return $elements; }
/** * * Adds DB_Table columns to a pre-existing HTML_QuickForm object. * * @author Ian Eure <*****@*****.**> * * @static * * @access public * * @param object &$form An HTML_QuickForm object. * * @param array $cols A sequential array of DB_Table column definitions * from which to create form elements. * * @param string $arrayName By default, the form will use the names * of the columns as the names of the form elements. If you pass * $arrayName, the column names will become keys in an array named * for this parameter. * * @return void * */ function addElements(&$form, $cols, $arrayName = null) { $elements =& DB_Table_QuickForm::getElements($cols, $arrayName); foreach (array_keys($elements) as $k) { $element =& $elements[$k]; if (is_array($element)) { $form->addGroup($element, $element->getName(), $col['qf_label']); } else { if (is_object($element)) { $form->addElement($element); } } } }