From 2991831c035a944712f2d906fbb4d99c7e93e02f Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 6 May 2009 14:45:44 +0000 Subject: Fix for ticket #72 --- core/libraries/MY_Forge.php | 5 ++- core/tests/DrawForm_Test.php | 84 ++++++++++++++++++++++++++++++++++++++++++++ core/views/form.html.php | 17 +++++++-- 3 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 core/tests/DrawForm_Test.php (limited to 'core') diff --git a/core/libraries/MY_Forge.php b/core/libraries/MY_Forge.php index 877fe62c..b302c8ef 100644 --- a/core/libraries/MY_Forge.php +++ b/core/libraries/MY_Forge.php @@ -24,14 +24,13 @@ class Forge extends Forge_Core { */ public function __construct($action=null, $title='', $method=null, $attr=array()) { parent::__construct($action, $title, $method, $attr); - $this->input("csrf")->type("hidden")->value(""); + $this->hidden("csrf")->value(""); } - /** * Use our own template */ public function render($template="form.html", $custom=false) { - $this->inputs["csrf"]->value(access::csrf_token()); + $this->hidden["csrf"]->value(access::csrf_token()); return parent::render($template, $custom); } diff --git a/core/tests/DrawForm_Test.php b/core/tests/DrawForm_Test.php new file mode 100644 index 00000000..68efbc4c --- /dev/null +++ b/core/tests/DrawForm_Test.php @@ -0,0 +1,84 @@ + "gTestGroupForm")); + $form->input("title")->label(t("Title")); + $form->textarea("description")->label(t("Text Area")); + $form->submit("")->value(t("Submit")); + $rendered = $form->__toString(); + + $expected = "
\n" . + "\n" . + " \n" . + "
\n"; + $this->assert_same($expected, $rendered); + } + + function group_test() { + $form = new Forge("test/controller", "", "post", array("id" => "gTestGroupForm")); + $group = $form->group("test_group")->label(t("Test Group")); + $group->input("title")->label(t("Title")); + $group->textarea("description")->label(t("Text Area")); + $group->submit("")->value(t("Submit")); + $rendered = $form->__toString(); + + $expected = "
\n" . + "\n" . + "
\n" . + " Test Group\n" . + "
    \n" . + "
  • \n" . + " \n" . + " \n" . + "
  • \n" . + "
  • \n" . + " \n" . + " \n" . + "
  • \n" . + "
  • \n" . + " \n" . + "
  • \n" . + "
\n" . + "
\n" . + "
\n"; + $this->assert_same($expected, $rendered); + } + +} + diff --git a/core/views/form.html.php b/core/views/form.html.php index 8c0e31e0..ec2a56a9 100644 --- a/core/views/form.html.php +++ b/core/views/form.html.php @@ -14,11 +14,19 @@ if (!function_exists("DrawForm")) { function DrawForm($inputs, $level=1) { $error_messages = array(); $prefix = str_repeat(" ", $level); + $haveGroup = false; + // On the first level, make sure we have a group if not add the