return $html;
}
+ private function form_element(array $data, string $type, string $text, array $class): string
+ {
+ $html = "";
+ $filtered_classes = $this->filter_meta_classes($class);
+
+ // Add additional attributes
+ $attributes = [
+ 'placeholder',
+ 'autocomplete',
+ 'required',
+ 'autofocus',
+ 'checked',
+ 'accept',
+ 'dirname',
+ 'disabled',
+ 'max',
+ 'maxlength',
+ 'min',
+ 'minlength',
+ 'multiple',
+ 'pattern',
+ 'readonly',
+ 'size',
+ 'src',
+ 'step',
+ 'value',
+ 'name',
+ 'title',
+ 'id',
+ ];
+
+ switch ($type) {
+ case 'text':
+ case 'email':
+ case 'number':
+ case 'password':
+ case 'range':
+ case 'tel':
+ case 'url':
+ case 'color':
+ case 'submit':
+ case 'file':
+ case 'hidden':
+ case 'image':
+ case 'button':
+ case 'date':
+ case 'datetime-local':
+ $html .= "<input type='$type'";
+ $html .= $this->class_html_or_empty($filtered_classes);
+
+ foreach ($attributes as $attribute) {
+ if (isset($data[$attribute])) {
+ $html .= " $attribute='" . $data[$attribute] . "'";
+ }
+ }
+
+ $html .= ">$text</input>";
+ break;
+
+ case 'radio':
+ case 'checkbox':
+ $html .= "<input type='$type'";
+ $html .= $this->class_html_or_empty($filtered_classes);
+
+ foreach ($attributes as $attribute) {
+ if (isset($data[$attribute])) {
+ $html .= " $attribute='" . $data[$attribute] . "'";
+ }
+ }
+
+ $html .= "/>";
+ // pls note: this one continues to the label. this is because the label is not a child of the input but a sibling
+ case 'label':
+ $html .= "<label";
+
+ $filtered_classes = $this->filter_meta_classes($class);
+ $html .= $this->class_html_or_empty($filtered_classes);
+
+ foreach ($attributes as $attribute) {
+ if (isset($data[$attribute])) {
+ if ($attribute == 'id') {
+ $html .= " for='" . $data[$attribute] . "'";
+ } else {
+ $html .= " $attribute='" . $data[$attribute] . "'";
+ }
+ }
+ }
+
+ if (isset($data['url']) && !empty($data['url'])) {
+ $html .= ">". $this->a($data['url'], $text, $data['title'], $filtered_classes) . "</label>";
+ } else {
+ $html .= ">$text</label>";
+ }
+
+ break;
+
+ case 'textarea':
+ $html .= "<textarea";
+ $html .= $this->class_html_or_empty($filtered_classes);
+
+ foreach ($attributes as $attribute) {
+ if (isset($data[$attribute])) {
+ $html .= " $attribute='" . $data[$attribute] . "'";
+ }
+ }
+
+ $html .= ">$text</textarea>";
+ break;
+
+ case 'select':
+ $html .= "<select";
+ $html .= $this->class_html_or_empty($filtered_classes);
+
+ foreach ($attributes as $attribute) {
+ if (isset($data[$attribute])) {
+ $html .= " $attribute='" . $data[$attribute] . "'";
+ }
+ }
+
+ $html .= ">$text</select>";
+ break;
+ }
+
+ if (!in_array("same-line", $class)) {
+ $html .= '<br';
+ $html .= $this->class_html_or_empty($filtered_classes);
+ $html .= '>';
+ }
+
+ return $html;
+ }
+
#endregion
#region html containers management
$is_p_closed = false;
// if class not empty add class
- $filtered_classes = $this->filter_meta_classes($class);
- $html .= $this->class_html_or_empty($filtered_classes);
+ $html .= $this->class_html_or_empty($this->filter_meta_classes($class));
$html .= '>';
} elseif (!$is_p_closed && !$open) {
return [$html, $is_p_closed];
}
+ private function open_or_close_form(bool $is_form_closed, array | null $class, bool $open): array
+ {
+ $html = "";
+
+ if ($is_form_closed && $open) {
+ $html .= '<form';
+ $is_form_closed = false;
+
+ // if class not empty add class
+ $html .= $this->class_html_or_empty($this->filter_meta_classes($class));
+
+ $html .= '>';
+ } elseif (!$is_form_closed && !$open) {
+ $html .= '</form>';
+ $is_form_closed = true;
+ }
+
+ return [$html, $is_form_closed];
+ }
+
private function open_or_close_ul(bool $is_list_closed, array | null $class, bool $open, string $text): array
{
$html = "";
$is_list_closed = false;
// if class not empty and text empty add class
- $filtered_classes = $this->filter_meta_classes($class);
if (empty($text)) {
- $html .= $this->class_html_or_empty($filtered_classes);
+ $html .= $this->class_html_or_empty($this->filter_meta_classes($class));
}
$html .= '>';
$is_p_closed = true;
$is_list_closed = true;
$is_div_closed = true;
+ $is_form_closed = true;
foreach ($data as $i => $line) {
$section = $this->str_val_or_empty($line, 'section');
break;
+ case in_array("form", $class):
+ // looks like this will be a form!
+ $html .= $this->form_h2_title($data, $i, $section, $url, $title, $class);
+ [$open_close_tag, $is_form_closed] = $this->open_or_close_form($is_form_closed, $class, OPEN);
+ $html .= $open_close_tag;
+
+ $html .= $this->form_element($line, $this->str_val_or_empty($line, 'type'), $this->str_val_or_empty($line, 'text'), $class);
+ //$html .= $this->form_form($line, $class, $url, $title, $this->str_val_or_empty($line, 'element'), $this->str_val_or_empty($line, 'type'));
+
+ break;
+
default:
// if previous iteration was diferent section close p
if ($i != 0 && $data[$i - 1]['section'] != $section) {
}
}
- // close last p
+ // close last elements
$html .= $this->open_or_close_p($is_p_closed, null, CLOSE)[0];
+ $html .= $this->open_or_close_form($is_form_closed, null, CLOSE)[0];
return $html;
}
return $html;
}
+ private function form_form(string $text, array $class, string $url, string $title, string $element, string $type): string
+ {
+ $html = "";
+ $filtered_classes = $this->filter_meta_classes($class);
+
+ return $html;
+ }
+
#endregion
#region array manipulation utils
*/
private function filter_meta_classes(array $class): array
{
+ $meta_classes = ["same-line", "no-space", "new-col", "list", "form"];
return array_diff($class, $meta_classes);
}