From a93461b231fb94f3a6a9df09a30557732201ddcc Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Mon, 14 Oct 2013 16:06:56 +0000 Subject: added new EasyGiant Library --- h-source/Library/Form/Form.php | 73 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 9 deletions(-) (limited to 'h-source/Library/Form/Form.php') diff --git a/h-source/Library/Form/Form.php b/h-source/Library/Form/Form.php index a1a9fda..d1899a4 100755 --- a/h-source/Library/Form/Form.php +++ b/h-source/Library/Form/Form.php @@ -97,7 +97,7 @@ class Form_Form { //function to create the HTML of the form //$values: an associative array ('entryName'=>'value') - //$subset: subset to print + //$subset: subset to print (comma seprated list of string or array) public function render($values = null, $subset = null) { @@ -116,23 +116,78 @@ class Form_Form { $fenctype = isset($this->enctype) ? " enctype=".$this->enctype." " : null; $htmlForm = "
\n"; - $subset = (isset($subset)) ? explode(',',$subset) : array_keys($values); + if (!isset($subset)) + { + $subset = array_keys($values); + } + else + { + $subset = !is_array($subset) ? explode(',',$subset) : $subset; + } +// $subset = (isset($subset)) ? explode(',',$subset) : array_keys($values); - foreach ($subset as $entry) + //first cicle: write the HTML of tabs if there are any + $tabsHtml = null; + $fCount = 0; + foreach ($subset as $key => $entry) { - - if (array_key_exists($entry,$this->entry)) + if (is_array($entry)) { - $value = array_key_exists($entry,$values) ? $values[$entry] : $this->entry[$entry]->defaultValue; - $htmlForm .= $this->entry[$entry]->render($value); + $currClass = $fCount === 0 ? "current_tab" : null; + $cleanKey = encode($key); + $tabsHtml .= "\t
  • $key
  • \n"; + $fCount++; + } + } + if (isset($tabsHtml)) + { + $htmlForm .= "\n"; + } + + $fCount = 0; + foreach ($subset as $k => $entry) + { + + $cleanK = encode($k); + if (!is_array($entry)) + { + if (array_key_exists($entry,$this->entry)) + { + $value = array_key_exists($entry,$values) ? $values[$entry] : $this->entry[$entry]->defaultValue; + $htmlForm .= $this->entry[$entry]->render($value); + } + } + else + { + $tHtml = null; + $displClass = $fCount === 0 ? null : "display_none"; + foreach ($entry as $e) + { + if (array_key_exists($e,$this->entry)) + { + $value = array_key_exists($e,$values) ? $values[$e] : $this->entry[$e]->defaultValue; + $tHtml .= $this->entry[$e]->render($value); + } + } + $htmlForm .= "
    $tHtml
    "; + $fCount++; } - } + $htmlForm .= "
    "; foreach ($this->submit as $name => $value) { - $htmlForm .= "
    \n\n
    \n"; + if (!is_array($value)) + { + $htmlForm .= "".Html_Form::submit($name, $value, null, $name).""; + } + else + { + array_unshift($value,$name); + $htmlForm .= call_user_func_array(array("Html_Form","submit"),$value); + } } + $htmlForm .= "
    "; $htmlForm .= "
    \n"; return $htmlForm; } -- cgit v1.2.3