- list($name, $type, $options) = split(' *', $field);
- if($options) $options = explode(',', $options);
- if(!$type) $type = $name;
+ $options = null;
+ $type = null;
+ $div = strpos($field, ' ');
+ if ($div === false) {
+ $div = strpos($field, "\t");
+ }
+ if ($div === false) {
+ if (isset($GLOBALS['types'][$field])) {
+ # if just one word, and it's a type, use it as name/caption and type
+ $type = $field;
+ }
+ } else {
+ $first_word = trim(substr($field, 0, $div));
+ if (isset($GLOBALS['types'][$first_word])) {
+ # if the first word (of multiple) is a type, remove it from the name/caption
+ $type = $first_word;
+ $field = trim(substr($field, $div + 1));
+ }
+ }
+ # see if there's an explicit name/caption splitter
+ $div = strpos($field, '|');
+ if ($div !== false) {
+ $name = trim(substr($field, 0, $div));
+ $caption = trim(substr($field, $div + 1));
+ if (isset($GLOBALS['types'][$name])) {
+ $type = $name;
+ } elseif (isset($GLOBALS['types'][strtolower($caption)])) {
+ $type = strtolower($caption);
+ }
+ } else {
+ $name = format_varname($field);
+ $caption = format_caption($field);
+ }
+
+ if ($type === null) {
+ $type = 'textbox';
+ }