summaryrefslogtreecommitdiff
path: root/themes/default/views/form.html.php
blob: 41bdc0f9c578328379f236e4a224099ce4b9ae91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<? defined("SYSPATH") or die("No direct script access."); ?>
<?
print($open);

// Not sure what to do with these, but at least show that we received them.
if ($class) {
  print "<!-- unused class in form.html.php: $class -->";
}
if ($title) {
  print "<!-- unused title in form.html.php: $title -->";
}

if (!function_exists("DrawForm")) {
  function DrawForm($inputs, $level=1) {
    $error_messages = array();
    $prefix = str_repeat("  ", $level);

    foreach ($inputs as $input) {
      if ($input->type == 'group') {
        print "$prefix<fieldset>\n";
        print "$prefix  <legend>$input->name</legend>\n";
        print "$prefix  <ul>\n";
        DrawForm($input->inputs, $level + 2);
        DrawForm($input->hidden, $level + 2);
        print "$prefix  </ul>\n";
        print "$prefix</fieldset>\n";
      } else {
        if ($input->error_messages()) {
          print "$prefix<li class=\"gError\">\n";
        } else if ($input->type) {
          print "$prefix<li>\n";
        } else {
          // no type means its a "hidden" so don't wrap it in <li>
        }
        if ($input->label()) {
          print "$prefix  {$input->label()}\n";
        }
        print "$prefix  {$input->render()}\n";
        if ($input->message()) {
          print "$prefix  <p>{$input->message()}</p>\n";
        }
        if ($input->error_messages()) {
          foreach ($input->error_messages() as $error_message) {
            print "$prefix  <p class=\"gError\">\n";
            print "$prefix    $error_message\n";
            print "$prefix  </p>\n";
          }
        }
        if ($input->type) {
          print "$prefix</li>\n";
        }
      }
    }
  }
}
DrawForm($inputs);

print($close);
?>