diff options
Diffstat (limited to 'h-source/Library/Form')
-rwxr-xr-x | h-source/Library/Form/Checkbox.php | 4 | ||||
-rwxr-xr-x | h-source/Library/Form/Entry.php | 3 | ||||
-rw-r--r-- | h-source/Library/Form/File.php | 4 | ||||
-rwxr-xr-x | h-source/Library/Form/Form.php | 49 | ||||
-rwxr-xr-x | h-source/Library/Form/Hidden.php | 4 | ||||
-rw-r--r-- | h-source/Library/Form/Html.php | 2 | ||||
-rwxr-xr-x | h-source/Library/Form/InputText.php | 4 | ||||
-rw-r--r-- | h-source/Library/Form/Password.php | 4 | ||||
-rwxr-xr-x | h-source/Library/Form/Radio.php | 4 | ||||
-rwxr-xr-x | h-source/Library/Form/Select.php | 4 | ||||
-rwxr-xr-x | h-source/Library/Form/Textarea.php | 4 |
11 files changed, 58 insertions, 28 deletions
diff --git a/h-source/Library/Form/Checkbox.php b/h-source/Library/Form/Checkbox.php index 497c097..91191a9 100755 --- a/h-source/Library/Form/Checkbox.php +++ b/h-source/Library/Form/Checkbox.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -39,7 +39,7 @@ class Form_Checkbox extends Form_Entry $returnString .= $wrap[1]; $returnString .= $this->getLabelTag(); $returnString .= $wrap[2]; - $returnString .= Html_Form::checkbox($this->entryName, $value, $this->options, $this->className,$this->idName); + $returnString .= Html_Form::checkbox($this->entryName, $value, $this->options, $this->className,$this->idName,$this->attributes); $returnString .= $wrap[3]; $returnString .="</div>\n"; $returnString .= $wrap[4]; diff --git a/h-source/Library/Form/Entry.php b/h-source/Library/Form/Entry.php index 6f45557..fa3b84f 100755 --- a/h-source/Library/Form/Entry.php +++ b/h-source/Library/Form/Entry.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -33,6 +33,7 @@ abstract class Form_Entry { public $labelClass = null; //the class of the tag of the label public $options = array(); //options (if the entry is a <select> entry or a radio button). Associative array or comma-divided list. public $reverse = null; //reverse label with value in select entries + public $attributes = null; //attributes of the field public $defaultValue = ''; public $wrap = array(); public $deleteButton = null; diff --git a/h-source/Library/Form/File.php b/h-source/Library/Form/File.php index ac9b8ab..f1e7d2d 100644 --- a/h-source/Library/Form/File.php +++ b/h-source/Library/Form/File.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -39,7 +39,7 @@ class Form_File extends Form_Entry $returnString .= $wrap[1]; $returnString .= $this->getLabelTag(); $returnString .= $wrap[2]; - $returnString .= Html_Form::fileUpload($this->entryName, $value, $this->className, $this->idName); + $returnString .= Html_Form::fileUpload($this->entryName, $value, $this->className, $this->idName, $this->attributes); if (is_array($this->deleteButton)) { $sname = isset($this->deleteButton[0]) ? $this->deleteButton[0] : 'delete_'.$this->entryName; diff --git a/h-source/Library/Form/Form.php b/h-source/Library/Form/Form.php index d1899a4..9b05c51 100755 --- a/h-source/Library/Form/Form.php +++ b/h-source/Library/Form/Form.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -25,6 +25,15 @@ if (!defined('EG')) die('Direct access not allowed!'); //create the HTML of the whole form class Form_Form { + //default attributes of the entries + public static $defaultEntryAttributes = array( + "entryClass" => null, + "className" => null, + "idName" => null, + "submitClass" => "btn btn-primary", + "formWrap" => null, + ); + public $entry = array(); //associative array containing the entries of the form (objects that inherit the class form_entryModel). Each element of the array corresponds to one field of the table public $action = null; //the action of the form @@ -53,8 +62,9 @@ class Form_Form { { throw new Exception("class <b>$entryObjName</b> not defined: the entry <b>$entryName</b> can't be set"); } + $this->entry[$entryName] = new $entryObjName($entryName); - $this->entry[$entryName]->labelString = $entryName.':'; + $this->entry[$entryName]->labelString = getFieldLabel($entryName); //set the type $this->entry[$entryName]->type = $entryType; if (isset($options)) @@ -72,17 +82,18 @@ class Form_Form { $type = array_key_exists('type',$entry) ? $entry['type'] : 'InputText'; $options = array_key_exists('options',$entry) ? $entry['options'] : null; $this->setEntry($name,$type,$options); - - $entryClass = array_key_exists('entryClass',$entry) ? $entry['entryClass'] : null; - $labelString = array_key_exists('labelString',$entry) ? $entry['labelString'] : "$name:"; - $idName = array_key_exists('idName',$entry) ? $entry['idName'] : null; - $className = array_key_exists('className',$entry) ? $entry['className'] : null; + + $entryClass = array_key_exists('entryClass',$entry) ? $entry['entryClass'] : self::$defaultEntryAttributes['entryClass']; + $labelString = array_key_exists('labelString',$entry) ? $entry['labelString'] : getFieldLabel($name); + $idName = array_key_exists('idName',$entry) ? $entry['idName'] : self::$defaultEntryAttributes['idName']; + $className = array_key_exists('className',$entry) ? $entry['className'] : self::$defaultEntryAttributes['className']; $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; $reverse = array_key_exists('reverse',$entry) ? $entry['reverse'] : null; - + $attributes = array_key_exists('attributes',$entry) ? $entry['attributes'] : null; + $this->entry[$name]->entryClass = $entryClass; $this->entry[$name]->labelString = $labelString; $this->entry[$name]->idName = $idName; @@ -92,6 +103,7 @@ class Form_Form { $this->entry[$name]->wrap = $wrap; $this->entry[$name]->deleteButton = $deleteButton; $this->entry[$name]->reverse = $reverse; + $this->entry[$name]->attributes = $attributes; } } @@ -113,7 +125,7 @@ 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; - $fenctype = isset($this->enctype) ? " enctype=".$this->enctype." " : null; + $fenctype = isset($this->enctype) ? " enctype='".$this->enctype."' " : null; $htmlForm = "<form $fname $fclass $fid action='".Url::getRoot($this->action)."' method='".$this->method."' $fenctype>\n"; if (!isset($subset)) @@ -179,7 +191,19 @@ class Form_Form { { if (!is_array($value)) { - $htmlForm .= "<span class='submit_entry_$value'>".Html_Form::submit($name, $value, null, $name)."</span>"; + $submitClass= ""; + if (!is_array(self::$defaultEntryAttributes['submitClass'])) + { + $submitClass = self::$defaultEntryAttributes['submitClass']; + } + else + { + if (array_key_exists($value,self::$defaultEntryAttributes['submitClass'])) + { + $submitClass = self::$defaultEntryAttributes['submitClass'][$value]; + } + } + $htmlForm .= "<span class='submit_entry_$value'>".Html_Form::submit($name, $value, $submitClass, $name)."</span>"; } else { @@ -189,6 +213,11 @@ class Form_Form { } $htmlForm .= "</div>"; $htmlForm .= "</form>\n"; + + if (isset(self::$defaultEntryAttributes["formWrap"]) and is_array(self::$defaultEntryAttributes["formWrap"]) and count(self::$defaultEntryAttributes["formWrap"]) === 2) + { + return self::$defaultEntryAttributes["formWrap"][0] . $htmlForm . self::$defaultEntryAttributes["formWrap"][1]; + } return $htmlForm; } diff --git a/h-source/Library/Form/Hidden.php b/h-source/Library/Form/Hidden.php index db86713..c2185b9 100755 --- a/h-source/Library/Form/Hidden.php +++ b/h-source/Library/Form/Hidden.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -33,7 +33,7 @@ class Form_Hidden extends Form_Entry public function render($value = null) { - $returnString = Html_Form::hidden($this->entryName, $value, $this->className, $this->idName); + $returnString = Html_Form::hidden($this->entryName, $value, $this->className, $this->idName, $this->attributes); return $returnString; } diff --git a/h-source/Library/Form/Html.php b/h-source/Library/Form/Html.php index e5c9989..a7181cc 100644 --- a/h-source/Library/Form/Html.php +++ b/h-source/Library/Form/Html.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Form/InputText.php b/h-source/Library/Form/InputText.php index 344264e..086c0a1 100755 --- a/h-source/Library/Form/InputText.php +++ b/h-source/Library/Form/InputText.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -39,7 +39,7 @@ class Form_InputText extends Form_Entry $returnString .= $wrap[1]; $returnString .= $this->getLabelTag(); $returnString .= $wrap[2]; - $returnString .= Html_Form::input($this->entryName, $value, $this->className, $this->idName); + $returnString .= Html_Form::input($this->entryName, $value, $this->className, $this->idName, $this->attributes); $returnString .= $wrap[3]; $returnString .="</div>\n"; $returnString .= $wrap[4]; diff --git a/h-source/Library/Form/Password.php b/h-source/Library/Form/Password.php index 9bfc68b..41fbc8e 100644 --- a/h-source/Library/Form/Password.php +++ b/h-source/Library/Form/Password.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -39,7 +39,7 @@ class Form_Password extends Form_Entry $returnString .= $wrap[1]; $returnString .= $this->getLabelTag(); $returnString .= $wrap[2]; - $returnString .= Html_Form::password($this->entryName, null, $this->className); + $returnString .= Html_Form::password($this->entryName, null, $this->className, $this->idName, $this->attributes); $returnString .= $wrap[3]; $returnString .="</div>\n"; $returnString .= $wrap[4]; diff --git a/h-source/Library/Form/Radio.php b/h-source/Library/Form/Radio.php index 4f596ed..10154be 100755 --- a/h-source/Library/Form/Radio.php +++ b/h-source/Library/Form/Radio.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -39,7 +39,7 @@ class Form_Radio extends Form_Entry $returnString .= $wrap[1]; $returnString .= $this->getLabelTag(); $returnString .= $wrap[2]; - $returnString .= Html_Form::radio($this->entryName,$value,$this->options,$this->className, 'after', $this->idName); + $returnString .= Html_Form::radio($this->entryName,$value,$this->options,$this->className, 'after', $this->idName, $this->attributes); $returnString .= $wrap[3]; $returnString .="</div>\n"; $returnString .= $wrap[4]; diff --git a/h-source/Library/Form/Select.php b/h-source/Library/Form/Select.php index 53d7632..8b2a634 100755 --- a/h-source/Library/Form/Select.php +++ b/h-source/Library/Form/Select.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -39,7 +39,7 @@ class Form_Select extends Form_Entry $returnString .= $wrap[1]; $returnString .= $this->getLabelTag(); $returnString .= $wrap[2]; - $returnString .= Html_Form::select($this->entryName,$value,$this->options,$this->className, $this->idName, $this->reverse); + $returnString .= Html_Form::select($this->entryName,$value,$this->options,$this->className, $this->idName, $this->reverse, $this->attributes); $returnString .= $wrap[3]; $returnString .="</div>\n"; $returnString .= $wrap[4]; diff --git a/h-source/Library/Form/Textarea.php b/h-source/Library/Form/Textarea.php index aaaf19e..f294b0a 100755 --- a/h-source/Library/Form/Textarea.php +++ b/h-source/Library/Form/Textarea.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -39,7 +39,7 @@ class Form_Textarea extends Form_Entry $returnString .= $wrap[1]; $returnString .= $this->getLabelTag(); $returnString .= $wrap[2]; - $returnString .= Html_Form::textarea($this->entryName, $value, $this->className, $this->idName); + $returnString .= Html_Form::textarea($this->entryName, $value, $this->className, $this->idName, $this->attributes); $returnString .= $wrap[3]; $returnString .="</div>\n"; $returnString .= $wrap[4]; |