diff options
author | Antonio Gallo <tonicucoz@gmail.com> | 2011-07-28 20:27:23 +0000 |
---|---|---|
committer | Antonio Gallo <tonicucoz@gmail.com> | 2011-07-28 20:27:23 +0000 |
commit | e7b3717614621f14695ab6ca6dda6dd17ba3d65c (patch) | |
tree | c8e6061aef3ff7bad5a17e1aecaf441d35e282cb /h-source/Library/Form | |
parent | 0de74c6879d263645770de3d6b3ce7123f5241d6 (diff) |
added new easygiant library
Diffstat (limited to 'h-source/Library/Form')
-rwxr-xr-x | h-source/Library/Form/Entry.php | 42 | ||||
-rw-r--r-- | h-source/Library/Form/File.php | 7 | ||||
-rwxr-xr-x | h-source/Library/Form/Form.php | 2 | ||||
-rwxr-xr-x | h-source/Library/Form/Textarea.php | 12 |
4 files changed, 56 insertions, 7 deletions
diff --git a/h-source/Library/Form/Entry.php b/h-source/Library/Form/Entry.php index 440ee2d..305f55f 100755 --- a/h-source/Library/Form/Entry.php +++ b/h-source/Library/Form/Entry.php @@ -32,6 +32,7 @@ abstract class Form_Entry { public $options = array(); //options (if the entry is a <select> entry or a radio button). Associative array or comma-divided list. public $defaultValue = ''; public $wrap = array(); + public $deleteButton = null; public $type = null; //the type of the entry //create the label of each entry of the form @@ -44,7 +45,32 @@ abstract class Form_Entry { //get the class of the entry public function getEntryClass() { - return isset($this->entryClass) ? $this->entryClass : 'formEntry'; + if (isset($this->entryClass)) + { + $class = $this->entryClass; + } + else + { + switch($this->type) + { + case 'InputText': + $class = 'form_input_text'; + break; + case 'File': + $class = 'form_input_file'; + break; + case 'Textarea': + $class = 'form_textarea'; + break; + case 'Password': + $class = 'form_input_text form_input_password'; + break; + default: + $class = 'form_input_text'; + break; + } + } + return $class; } public function getWrapElements($value = null) @@ -52,7 +78,19 @@ abstract class Form_Entry { //replace the ;;value;; variable for ($i = 0; $i < count($this->wrap); $i++) { - $this->wrap[$i] = str_replace(';;value;;',$value,$this->wrap[$i]); + if ( preg_match('/;;(.*)\|value;;/',$this->wrap[$i],$m) ) + { + if (!function_exists($m[1])) { + throw new Exception('Error in <b>'.__METHOD__.'</b>: function <b>'.$m[1].'</b> does not exists..'); + } + //apply the function + $v = call_user_func($m[1],$value); + $this->wrap[$i] = str_replace(";;".$m[1]."|value;;",$v,$this->wrap[$i]); + } + else if ( preg_match('/;;value;;/',$this->wrap[$i]) ) + { + $this->wrap[$i] = str_replace(';;value;;',$value,$this->wrap[$i]); + } } $wrap[0] = isset($this->wrap[0]) ? $this->wrap[0] : null; diff --git a/h-source/Library/Form/File.php b/h-source/Library/Form/File.php index 48030f7..951b3d4 100644 --- a/h-source/Library/Form/File.php +++ b/h-source/Library/Form/File.php @@ -38,6 +38,13 @@ class Form_File extends Form_Entry $returnString .= $this->getLabelTag(); $returnString .= $wrap[2]; $returnString .= Html_Form::fileUpload($this->entryName, $value, $this->className, $this->idName); + if (is_array($this->deleteButton)) + { + $sname = isset($this->deleteButton[0]) ? $this->deleteButton[0] : 'delete_'.$this->entryName; + $svalue = isset($this->deleteButton[1]) ? $this->deleteButton[1] : 'delete'; + $sclass = isset($this->deleteButton[2]) ? "class='".$this->deleteButton[2]."'" : null; + $returnString .= "<input $sclass type='submit' name='$sname' value='$svalue'>\n"; + } $returnString .= $wrap[3]; $returnString .="</div>\n"; $returnString .= $wrap[4]; diff --git a/h-source/Library/Form/Form.php b/h-source/Library/Form/Form.php index 9aba086..a20327f 100755 --- a/h-source/Library/Form/Form.php +++ b/h-source/Library/Form/Form.php @@ -78,6 +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(); + $deleteButton = array_key_exists('deleteButton',$entry) ? $entry['deleteButton'] : null; $this->entry[$name]->entryClass = $entryClass; $this->entry[$name]->labelString = $labelString; @@ -86,6 +87,7 @@ class Form_Form { $this->entry[$name]->labelClass = $labelClass; $this->entry[$name]->defaultValue = $defaultValue; $this->entry[$name]->wrap = $wrap; + $this->entry[$name]->deleteButton = $deleteButton; } } diff --git a/h-source/Library/Form/Textarea.php b/h-source/Library/Form/Textarea.php index 33b8bc3..ba51fe9 100755 --- a/h-source/Library/Form/Textarea.php +++ b/h-source/Library/Form/Textarea.php @@ -31,14 +31,16 @@ class Form_Textarea 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::textarea($this->entryName, $value, $this->className, $this->idName); + $returnString .= $this->getLabelTag(); $returnString .= $wrap[2]; + $returnString .= Html_Form::textarea($this->entryName, $value, $this->className, $this->idName); + $returnString .= $wrap[3]; $returnString .="</div>\n"; + $returnString .= $wrap[4]; return $returnString; } |