. Add formular name to forms
authorJoey Schulze <joey@infodrom.org>
Thu, 25 Feb 2010 16:28:44 +0000 (17:28 +0100)
committerJoey Schulze <joey@infodrom.org>
Thu, 25 Feb 2010 16:28:44 +0000 (17:28 +0100)
 . Support numeric fields (for later syntax check)
 . Add boolean fields represented as checkbox

lib/mask.php

index f2503cc..b60a650 100644 (file)
@@ -10,7 +10,7 @@
 #   return $ret;
 # }
 
-function build_form($fields)
+function build_form($name, $fields)
 {
   $ret = array();
 
@@ -18,15 +18,19 @@ function build_form($fields)
   $ret[] = '<form id="form_edit">';
 
   $ret[] = '<input type="hidden" id="edit_id" name="id" value="">';
+  $ret[] = sprintf('<input type="hidden" id="edit_source" name="source" value="%s">', $name);
 
   foreach ($fields as $id => $info) {
-    if ($info['type'] == 'text') {
+    if ($info['type'] == 'text' || $info['type'] == 'number') {
       $v = array('id="edit_'.$id.'"',
                 'name="'.$id.'"',
                 'size="'.$info['size'].'"',
                 'type="text"');
       $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
       $ret[] = sprintf('<input %s><br>', implode(' ', $v));
+    } elseif ($info['type'] == 'boolean') {
+      $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
+      $ret[] = sprintf('<input type="checkbox" id="edit_%s" name="%s"><br>', $id, $id);
     } elseif ($info['type'] == 'select') {
       $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
       $ret[] = sprintf('<select id="edit_%s" name="%s">', $id, $id);
@@ -35,8 +39,6 @@ function build_form($fields)
       foreach ($options as $row)
        $ret[] = sprintf('<option value="%s">%s</option>', $row['id'], $row['text']);
       $ret[] = '</select><br>';
-
-      error_log('type = select');
     } elseif ($info['type'] == 'date') {
       error_log('type = date');
     }
@@ -172,7 +174,7 @@ function mask($name)
     $ret = build_mask($name, $mask);
 
   if (array_key_exists('edit', $mask))
-    $ret = array_merge($ret, build_form($mask['edit']));
+    $ret = array_merge($ret, build_form($name, $mask['edit']));
 
   return implode("\n", $ret);
 }