aboutsummaryrefslogtreecommitdiff
path: root/h-source/Library/Form
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2011-05-08 15:26:22 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2011-05-08 15:26:22 +0000
commitafc02bc1c3db9ffe8c9bf660c8aa08666752edfb (patch)
tree9a02b06b390dd0c1e796474b888e92c245473424 /h-source/Library/Form
parent7fdac301801bc44f6fdb343187413bdfd2d5366c (diff)
h-source:added new EasyGiant SVN version
Diffstat (limited to 'h-source/Library/Form')
-rwxr-xr-xh-source/Library/Form/Checkbox.php12
-rwxr-xr-xh-source/Library/Form/Entry.php10
-rw-r--r--h-source/Library/Form/File.php47
-rwxr-xr-xh-source/Library/Form/Form.php9
-rwxr-xr-xh-source/Library/Form/InputText.php12
-rw-r--r--h-source/Library/Form/Password.php12
-rwxr-xr-xh-source/Library/Form/Radio.php12
-rwxr-xr-xh-source/Library/Form/Select.php12
8 files changed, 97 insertions, 29 deletions
diff --git a/h-source/Library/Form/Checkbox.php b/h-source/Library/Form/Checkbox.php
index a606e76..4074210 100755
--- a/h-source/Library/Form/Checkbox.php
+++ b/h-source/Library/Form/Checkbox.php
@@ -31,14 +31,16 @@ class Form_Checkbox extends Form_Entry
public function render($value = null)
{
- $wrap = $this->getWrapElements();
- $returnString = "<div class='".$this->getEntryClass()."'>\n\t";
- $returnString .= $wrap[0];
- $returnString .= $this->getLabelTag();
+ $wrap = $this->getWrapElements($value);
+ $returnString = $wrap[0];
+ $returnString .= "<div class='".$this->getEntryClass()."'>\n\t";
$returnString .= $wrap[1];
- $returnString .= Html_Form::checkbox($this->entryName, $value, $this->options, $this->className,$this->idName);
+ $returnString .= $this->getLabelTag();
$returnString .= $wrap[2];
+ $returnString .= Html_Form::checkbox($this->entryName, $value, $this->options, $this->className,$this->idName);
+ $returnString .= $wrap[3];
$returnString .="</div>\n";
+ $returnString .= $wrap[4];
return $returnString;
}
diff --git a/h-source/Library/Form/Entry.php b/h-source/Library/Form/Entry.php
index 2582557..440ee2d 100755
--- a/h-source/Library/Form/Entry.php
+++ b/h-source/Library/Form/Entry.php
@@ -47,11 +47,19 @@ abstract class Form_Entry {
return isset($this->entryClass) ? $this->entryClass : 'formEntry';
}
- public function getWrapElements()
+ public function getWrapElements($value = null)
{
+ //replace the ;;value;; variable
+ for ($i = 0; $i < count($this->wrap); $i++)
+ {
+ $this->wrap[$i] = str_replace(';;value;;',$value,$this->wrap[$i]);
+ }
+
$wrap[0] = isset($this->wrap[0]) ? $this->wrap[0] : null;
$wrap[1] = isset($this->wrap[1]) ? $this->wrap[1] : null;
$wrap[2] = isset($this->wrap[2]) ? $this->wrap[2] : null;
+ $wrap[3] = isset($this->wrap[3]) ? $this->wrap[3] : null;
+ $wrap[4] = isset($this->wrap[4]) ? $this->wrap[4] : null;
return $wrap;
}
diff --git a/h-source/Library/Form/File.php b/h-source/Library/Form/File.php
new file mode 100644
index 0000000..48030f7
--- /dev/null
+++ b/h-source/Library/Form/File.php
@@ -0,0 +1,47 @@
+<?php
+
+// EasyGiant, a web software to build a community of people that want to share their hardware information.
+// Copyright (C) 2009 - 2010 Antonio Gallo (h-source-copyright.txt)
+//
+// This file is part of EasyGiant
+//
+// EasyGiant is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// EasyGiant is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with EasyGiant. If not, see <http://www.gnu.org/licenses/>.
+
+if (!defined('EG')) die('Direct access not allowed!');
+
+//create the HTML of a file upload entry
+class Form_File extends Form_Entry
+{
+
+ public function __construct($entryName = null)
+ {
+ $this->entryName = $entryName;
+ }
+
+ public function render($value = null)
+ {
+ $wrap = $this->getWrapElements($value);
+ $returnString = $wrap[0];
+ $returnString .= "<div class='".$this->getEntryClass()."'>\n\t";
+ $returnString .= $wrap[1];
+ $returnString .= $this->getLabelTag();
+ $returnString .= $wrap[2];
+ $returnString .= Html_Form::fileUpload($this->entryName, $value, $this->className, $this->idName);
+ $returnString .= $wrap[3];
+ $returnString .="</div>\n";
+ $returnString .= $wrap[4];
+ return $returnString;
+ }
+
+}
diff --git a/h-source/Library/Form/Form.php b/h-source/Library/Form/Form.php
index 9705666..9aba086 100755
--- a/h-source/Library/Form/Form.php
+++ b/h-source/Library/Form/Form.php
@@ -31,12 +31,14 @@ class Form_Form {
public $id = null;
public $submit = array(); //the submit entries array('name'=>'value')
public $method = 'POST'; //the transmission method: POST/GET
+ public $enctype = null; //enctype attribute of the form
- public function __construct($action,$submit = array('generalAction'=>'save'),$method = 'POST')
+ public function __construct($action,$submit = array('generalAction'=>'save'),$method = 'POST',$enctype = null)
{
$this->action = $action; //action of the form: controller/action
$this->submit = $submit;
$this->method = $method;
+ $this->enctype = $enctype;
}
//method to manage the $this->entry associative array
@@ -76,7 +78,7 @@ class Form_Form {
$labelClass = array_key_exists('labelClass',$entry) ? $entry['labelClass'] : null;
$defaultValue = array_key_exists('defaultValue',$entry) ? $entry['defaultValue'] : null;
$wrap = array_key_exists('wrap',$entry) ? $entry['wrap'] : array();
-
+
$this->entry[$name]->entryClass = $entryClass;
$this->entry[$name]->labelString = $labelString;
$this->entry[$name]->idName = $idName;
@@ -105,7 +107,8 @@ class Form_Form {
$fid = isset($this->id) ? "id='".$this->id."'" : null;
$fname = isset($this->name) ? "name='".$this->name."'" : null;
$fclass = isset($this->className) ? "class='".$this->className."'" : null;
- $htmlForm = "<form $fname $fclass $fid action='".Url::getRoot($this->action)."' method='".$this->method."'>\n";
+ $fenctype = isset($this->enctype) ? " enctype=".$this->enctype." " : null;
+ $htmlForm = "<form $fname $fclass $fid action='".Url::getRoot($this->action)."' method='".$this->method."' $fenctype>\n";
$subset = (isset($subset)) ? explode(',',$subset) : array_keys($values);
diff --git a/h-source/Library/Form/InputText.php b/h-source/Library/Form/InputText.php
index 02315a6..5943fb9 100755
--- a/h-source/Library/Form/InputText.php
+++ b/h-source/Library/Form/InputText.php
@@ -31,14 +31,16 @@ class Form_InputText extends Form_Entry
public function render($value = null)
{
- $wrap = $this->getWrapElements();
- $returnString = "<div class='".$this->getEntryClass()."'>\n\t";
- $returnString .= $wrap[0];
- $returnString .= $this->getLabelTag();
+ $wrap = $this->getWrapElements($value);
+ $returnString = $wrap[0];
+ $returnString .= "<div class='".$this->getEntryClass()."'>\n\t";
$returnString .= $wrap[1];
- $returnString .= Html_Form::input($this->entryName, $value, $this->className, $this->idName);
+ $returnString .= $this->getLabelTag();
$returnString .= $wrap[2];
+ $returnString .= Html_Form::input($this->entryName, $value, $this->className, $this->idName);
+ $returnString .= $wrap[3];
$returnString .="</div>\n";
+ $returnString .= $wrap[4];
return $returnString;
}
diff --git a/h-source/Library/Form/Password.php b/h-source/Library/Form/Password.php
index 02500af..1ac4492 100644
--- a/h-source/Library/Form/Password.php
+++ b/h-source/Library/Form/Password.php
@@ -31,14 +31,16 @@ class Form_Password extends Form_Entry
public function render($value = null)
{
- $wrap = $this->getWrapElements();
- $returnString = "<div class='".$this->getEntryClass()."'>\n\t";
- $returnString .= $wrap[0];
- $returnString .= $this->getLabelTag();
+ $wrap = $this->getWrapElements($value);
+ $returnString = $wrap[0];
+ $returnString .= "<div class='".$this->getEntryClass()."'>\n\t";
$returnString .= $wrap[1];
- $returnString .= Html_Form::password($this->entryName, null, $this->className);
+ $returnString .= $this->getLabelTag();
$returnString .= $wrap[2];
+ $returnString .= Html_Form::password($this->entryName, null, $this->className);
+ $returnString .= $wrap[3];
$returnString .="</div>\n";
+ $returnString .= $wrap[4];
return $returnString;
}
diff --git a/h-source/Library/Form/Radio.php b/h-source/Library/Form/Radio.php
index 49137c0..a10726a 100755
--- a/h-source/Library/Form/Radio.php
+++ b/h-source/Library/Form/Radio.php
@@ -31,14 +31,16 @@ class Form_Radio extends Form_Entry
public function render($value = null)
{
- $wrap = $this->getWrapElements();
- $returnString = "<div class='".$this->getEntryClass()."'>\n\t";
- $returnString .= $wrap[0];
- $returnString .= $this->getLabelTag();
+ $wrap = $this->getWrapElements($value);
+ $returnString = $wrap[0];
+ $returnString .= "<div class='".$this->getEntryClass()."'>\n\t";
$returnString .= $wrap[1];
- $returnString .= Html_Form::radio($this->entryName,$value,$this->options,$this->className, 'after', $this->idName);
+ $returnString .= $this->getLabelTag();
$returnString .= $wrap[2];
+ $returnString .= Html_Form::radio($this->entryName,$value,$this->options,$this->className, 'after', $this->idName);
+ $returnString .= $wrap[3];
$returnString .="</div>\n";
+ $returnString .= $wrap[4];
return $returnString;
}
diff --git a/h-source/Library/Form/Select.php b/h-source/Library/Form/Select.php
index db88124..884b0b2 100755
--- a/h-source/Library/Form/Select.php
+++ b/h-source/Library/Form/Select.php
@@ -31,14 +31,16 @@ class Form_Select extends Form_Entry
public function render($value = null)
{
- $wrap = $this->getWrapElements();
- $returnString = "<div class='".$this->getEntryClass()."'>\n\t";
- $returnString .= $wrap[0];
- $returnString .= $this->getLabelTag();
+ $wrap = $this->getWrapElements($value);
+ $returnString = $wrap[0];
+ $returnString .= "<div class='".$this->getEntryClass()."'>\n\t";
$returnString .= $wrap[1];
- $returnString .= Html_Form::select($this->entryName,$value,$this->options,$this->className, $this->idName);
+ $returnString .= $this->getLabelTag();
$returnString .= $wrap[2];
+ $returnString .= Html_Form::select($this->entryName,$value,$this->options,$this->className, $this->idName);
+ $returnString .= $wrap[3];
$returnString .="</div>\n";
+ $returnString .= $wrap[4];
return $returnString;
}