Commit 583ec301 authored by Carsten  Rose's avatar Carsten Rose
Browse files

AbstractBuildForm: created a base 'head()' function.

BuildFormPlain: moved 'head()' to AbstractBuildForm.
BuilFormTable: adjusted to use generic getFormTag().
parent 7d21f74a
......@@ -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
......@@ -186,7 +186,7 @@ BUTTONS;
*
* @return string
*/
private function getFormTag() {
public function getFormTag() {
$attribute = $this->getFormTagAtrributes();
......
......@@ -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
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment