/** * Instantiantiate a field given its short class name * @param string $formfield the short name of a form field (e.g. STRING_LINE or DATE_YMD) * @param string $name The name of the field * @param array $args. Defaults to empty array. The field arguments passed to the constructor * @returns mixed I2CE_FormField or false on failure */ public static function createField($formfield, $name, $args = array()) { $i2ce_config = I2CE::getConfig()->modules->forms; if (!$i2ce_config->is_scalar("FORMFIELD/{$formfield}")) { I2CE::raiseError("Form field type ({$formfield}) has not been registered"); return false; } $classname = $i2ce_config->FORMFIELD->{$formfield}; if (!class_exists($classname)) { I2CE::raiseError("{$formfield} is assoicated to class {$classname} which cannot be found"); return false; } @($field = new $classname($name, $args)); if (!$field instanceof I2CE_FormField) { I2CE::raiserError("{$formfield} is not associated to an instance of I2CE_FormField"); return false; } return $field; }