From 583ec301ed30bea82f3648b8a94f6cb574c604f5 Mon Sep 17 00:00:00 2001 From: Carsten Rose <carsten.rose@math.uzh.ch> Date: Sat, 30 Jan 2016 18:36:53 +0100 Subject: [PATCH] AbstractBuildForm: created a base 'head()' function. BuildFormPlain: moved 'head()' to AbstractBuildForm. BuilFormTable: adjusted to use generic getFormTag(). --- qfq/AbstractBuildForm.php | 151 +++++++++++++++++++------------------ qfq/BuildFormBootstrap.php | 2 +- qfq/BuildFormPlain.php | 12 --- qfq/BuildFormTable.php | 2 +- 4 files changed, 81 insertions(+), 86 deletions(-) diff --git a/qfq/AbstractBuildForm.php b/qfq/AbstractBuildForm.php index 27ddf5805..46f14ced4 100644 --- a/qfq/AbstractBuildForm.php +++ b/qfq/AbstractBuildForm.php @@ -126,7 +126,85 @@ abstract class AbstractBuildForm { return $html; } - abstract public function head(); + public function head() { + $html = ''; + + $html .= $this->wrapItem(WRAP_SETUP_TITLE, $this->formSpec['title'], true); + $html .= $this->getFormTag(); + + return $html; + } + + /** + * @param $item + * @param $value + * @param bool|false $flagOmitEmpty + * @return string + */ + public function wrapItem($item, $value, $flagOmitEmpty = false) { + if ($flagOmitEmpty && $value === "") + return ''; + return $this->wrap[$item][WRAP_SETUP_START] . $value . $this->wrap[$item][WRAP_SETUP_END]; + } + + /** + * Rreturns complete '<form ...>' + * + * @return string + */ + public function getFormTag() { + + $attribute = $this->getFormTagAtrributes(); + + return '<form ' . OnArray::toString($attribute, '=', ' ', "'") . '>'; + } + + /** + * Build an assoc array with standard form attributes. + * + * @return mixed + */ + public function getFormTagAtrributes() { + + $attribute['method'] = 'post'; + $attribute['action'] = $this->getActionUrl(); + $attribute['target'] = '_top'; + $attribute['accept-charset'] = 'UTF-8'; + $attribute['autocomplete'] = 'on'; + $attribute['enctype'] = $this->getEncType(); + + return $attribute; + } + + /** + * Builds the HTML 'form'-tag inlcuding all attributes and target. + * + * @return string + * @throws DbException + */ + public function getActionUrl() { + + $queryStringArray['s'] = $this->store->getVar(SIP_SIP, STORE_SIP); + + Support::appendTypo3ParameterToArray($queryStringArray); + + return basename($_SERVER['SCRIPT_NAME']) . "?" . Support::arrayToQueryString($queryStringArray); + } + + /** + * Determines the enctype. + * + * See: https://www.w3.org/wiki/HTML/Elements/form#HTML_Attributes + * + * @return string + * @throws DbException + */ + public function getEncType() { + + $result = $this->db->sql("SELECT id FROM FormElement AS fe WHERE fe.formId=? AND fe.type='upload' LIMIT 1", ROW_EMPTY_IS_OK, [$this->formSpec['id']], 'Look for Formelement.type="upload"'); + return (count($result) === 1) ? 'multipart/form-data' : 'application/x-www-form-urlencoded'; + + } abstract public function getProcessFilter(); @@ -197,18 +275,6 @@ abstract class AbstractBuildForm { abstract public function buildRowSubrecord($formElement, $elementHtml); - /** - * @param $item - * @param $value - * @param bool|false $flagOmitEmpty - * @return string - */ - public function wrapItem($item, $value, $flagOmitEmpty = false) { - if ($flagOmitEmpty && $value === "") - return ''; - return $this->wrap[$item][WRAP_SETUP_START] . $value . $this->wrap[$item][WRAP_SETUP_END]; - } - /** * @param $tag * @param $value @@ -1001,64 +1067,5 @@ abstract class AbstractBuildForm { return $html; } - /** - * Rreturns complete '<form ...>' - * - * @return string - */ - private function getFormTag() { - - $attribute = $this->getFormTagAtrributes(); - - return '<form ' . OnArray::toString($attribute, '=', ' ', "'") . '>'; - } - - /** - * Build an assoc array with standard form attributes. - * - * @return mixed - */ - public function getFormTagAtrributes() { - - $attribute['method'] = 'post'; - $attribute['action'] = $this->getActionUrl(); - $attribute['target'] = '_top'; - $attribute['accept-charset'] = 'UTF-8'; - $attribute['autocomplete'] = 'on'; - $attribute['enctype'] = $this->getEncType(); - - return $attribute; - } - - /** - * Builds the HTML 'form'-tag inlcuding all attributes and target. - * - * @return string - * @throws DbException - */ - public function getActionUrl() { - - $queryStringArray['s'] = $this->store->getVar(SIP_SIP, STORE_SIP); - - Support::appendTypo3ParameterToArray($queryStringArray); - - return basename($_SERVER['SCRIPT_NAME']) . "?" . Support::arrayToQueryString($queryStringArray); - } - - /** - * Determines the enctype. - * - * See: https://www.w3.org/wiki/HTML/Elements/form#HTML_Attributes - * - * @return string - * @throws DbException - */ - public function getEncType() { - - $result = $this->db->sql("SELECT id FROM FormElement AS fe WHERE fe.formId=? AND fe.type='upload' LIMIT 1", ROW_EMPTY_IS_OK, [$this->formSpec['id']], 'Look for Formelement.type="upload"'); - return (count($result) === 1) ? 'multipart/form-data' : 'application/x-www-form-urlencoded'; - - } - } \ No newline at end of file diff --git a/qfq/BuildFormBootstrap.php b/qfq/BuildFormBootstrap.php index a04d5f6ea..75d5d76c4 100644 --- a/qfq/BuildFormBootstrap.php +++ b/qfq/BuildFormBootstrap.php @@ -186,7 +186,7 @@ BUTTONS; * * @return string */ - private function getFormTag() { + public function getFormTag() { $attribute = $this->getFormTagAtrributes(); diff --git a/qfq/BuildFormPlain.php b/qfq/BuildFormPlain.php index 8b114382f..7538baedd 100644 --- a/qfq/BuildFormPlain.php +++ b/qfq/BuildFormPlain.php @@ -55,18 +55,6 @@ class BuildFormPlain extends AbstractBuildForm { return $this->elements($this->store->getVar(SIP_RECORD_ID, STORE_SIP), FORM_ELEMENTS_SUBRECORD); } - /** - * @return string - */ - public function head() { - $html = ''; - - $html .= $this->wrapItem(WRAP_SETUP_TITLE, $this->formSpec['title'], true); - $html .= '<form action="?" method="post" target="_top" accept-charset="UTF-8">'; - - return $html; - } - /** * @param $htmlFormElementId * @param $formElement diff --git a/qfq/BuildFormTable.php b/qfq/BuildFormTable.php index 8ec84dcd5..d4f1edd1a 100644 --- a/qfq/BuildFormTable.php +++ b/qfq/BuildFormTable.php @@ -64,7 +64,7 @@ class BuildFormTable extends AbstractBuildForm { $html = ''; $html .= $this->wrapItem(WRAP_SETUP_TITLE, $this->formSpec['title'], true); - $html .= '<form action="?" method="post" target="_top" accept-charset="UTF-8">'; + $html .= $this->getFormTag(); $html .= '<table>'; return $html; -- GitLab