diff --git a/htdocs/core/class/html.formsetup.class.php b/htdocs/core/class/html.formsetup.class.php index 6f2ec2acfb6..a8ed08587ed 100644 --- a/htdocs/core/class/html.formsetup.class.php +++ b/htdocs/core/class/html.formsetup.class.php @@ -44,6 +44,47 @@ class FormSetup /** @var int */ protected $maxItemRank; + /** + * this is an html string display before output form + * @var string + */ + public $htmlBeforeOutputForm = ''; + + /** + * this is an html string display after output form + * @var string + */ + public $htmlAfterOutputForm = ''; + + /** + * this is an html string display on buttons zone + * @var string + */ + public $htmlOutputMoreButton = ''; + + + /** + * + * @var array + */ + public $formAttributes = array( + 'action' => '', // set in __construct + 'method' => 'POST' + ); + + /** + * an list of hidden inputs used only in edit mode + * @var array + */ + public $formHiddenInputs = array(); + + + /** + * the value of action attribute of form + * @var string + */ + public $formAction; + /** * Constructor * @@ -55,6 +96,11 @@ class FormSetup global $langs; $this->db = $db; $this->form = new Form($this->db); + $this->formAttributes['action'] = $_SERVER["PHP_SELF"]; + + $this->formHiddenInputs['token'] = newToken(); + $this->formHiddenInputs['action'] = 'update'; + if ($outputLangs) { $this->langs = $outputLangs; @@ -63,6 +109,38 @@ class FormSetup } } + /** + * a quick method to sanitize html attributes + * @param string $var the string to sanitize + * @return string + */ + static public function sanitizeHtmlAttribute($var) + { + $var = preg_replace("/\r|\n/", "", $var); + return htmlspecialchars($var, ENT_QUOTES); + } + + /** + * Generae an attributes string form an input array + * @param array $attributes an array of attributes keys and values, + * @return string + */ + static public function generateAttributesStringFromArray($attributes) + { + $Aattr = array(); + if (is_array($attributes)) { + foreach ($attributes as $attribute => $value) { + if (is_array($value) || is_object($value)) { + continue; + } + $Aattr[] = $attribute.'="'.self::sanitizeHtmlAttribute($value).'"'; + } + } + + return !empty($Aattr)?implode(' ', $Aattr):''; + } + + /** * @param bool $editMode true will display output on edit mod * @return string @@ -83,12 +161,70 @@ class FormSetup if ($reshook > 0) { return $hookmanager->resPrint; } else { - $out = ''; + $out = ''; + $out.= $this->htmlBeforeOutputForm; + if ($editMode) { - $out .= ''; + $out.= '