commit a283d2cf371bd1fda046595448d91f616458d990 Author: Kavalar Date: Fri Mar 14 17:42:58 2025 +0300 first diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8925195 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +vendor +composer.lock \ No newline at end of file diff --git a/app/active_fields/TextActiveField.php b/app/active_fields/TextActiveField.php new file mode 100644 index 0000000..b6879b9 --- /dev/null +++ b/app/active_fields/TextActiveField.php @@ -0,0 +1,18 @@ +"; + $html .= ""; + return $html; + } + +} \ No newline at end of file diff --git a/app/forms/UserForm.php b/app/forms/UserForm.php new file mode 100644 index 0000000..adfe9b9 --- /dev/null +++ b/app/forms/UserForm.php @@ -0,0 +1,15 @@ + [ + 'label' => 'Имя', + 'type' => 'text', + 'id' => 'user_name', + 'class' => 'inputForm', + ], + 'email' => [ + 'label' => 'Email', + 'type' => 'email', + 'id' => 'user_email', + 'class' => 'inputForm', + ], + 'tg' => [ + 'label' => 'Telegram', + 'type' => 'text', + 'id' => 'user_tg', + 'class' => 'inputForm', + ], + 'phone' => [ + 'label' => 'Телефон', + 'type' => 'number', + 'id' => 'user_phone', + 'class' => 'inputForm', + ], +]; + +$form = new UserForm([ + 'action' => 'save_user.php', + 'method' => 'POST' +]); +$form->load($inputs); +$form->field(type: "text", name: "additional_email", params: [ + 'class' => 'additional_email inputForm', + 'label' => 'Дполнительный email', + 'id' => 'additional_email', +]); +$form->render(); + +$form2 = new UserForm([ + 'action' => "save_client.php", + 'method' => 'POST' +]); + +$form2->field(type: "text", name: "user_id", params: [ + 'class' => 'inputForm', + 'label' => 'Пользователь', + 'id' => 'user_id', +]); +$form2->render(); + diff --git a/form_helper.php b/form_helper.php new file mode 100644 index 0000000..953c34b --- /dev/null +++ b/form_helper.php @@ -0,0 +1,11 @@ + $input) { + echo "
"; + echo ""; + } + } +} \ No newline at end of file diff --git a/header.php b/header.php new file mode 100644 index 0000000..7c91d2a --- /dev/null +++ b/header.php @@ -0,0 +1,18 @@ + + .inputForm { + color: RED; + margin: 10px; + } + .additional_email { + color: #2c35cc; + } + + +"; \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..5eac747 --- /dev/null +++ b/index.php @@ -0,0 +1,23 @@ +data = $data; + } + + public function fetchField() + { + + } + +} \ No newline at end of file diff --git a/src/Form.php b/src/Form.php new file mode 100644 index 0000000..ae793b5 --- /dev/null +++ b/src/Form.php @@ -0,0 +1,86 @@ +formParams = $formParams; + $this->createParams(); + } + + protected function _start(): void + { + $this->html .= "
formParamsStr>"; + } + + protected function _end(): void + { + $this->html .= "
"; + } + + public function render(): void + { + $this->_start(); + $this->createFields(); + $this->_end(); + echo $this->html; + } + + public function fetch(): string + { + $this->_start(); + $this->createFields(); + $this->_end(); + return $this->html; + } + + public function field(string $type, string $name, array $params = []): void + { + $fieldArr = []; + $fieldArr['type'] = $type; + $fieldArr = array_merge($fieldArr, $params); + $this->data[$name] = $fieldArr; + } + + public function activeField() + { + + } + + /** + * @param array $arr + * @return void + */ + public function load(array $arr): void + { + $this->data = $arr; + } + + public function createFields(): void + { + foreach ($this->data as $key => $input) { + $this->html .= "
"; + $this->html .= ""; + } + } + + protected function createParams(): void + { + foreach ($this->formParams as $key => $param){ + $this->formParamsStr .= " $key='$param'"; + } + } + + private function setSome() + { + + } + +} \ No newline at end of file diff --git a/views/index.php b/views/index.php new file mode 100644 index 0000000..044f5af --- /dev/null +++ b/views/index.php @@ -0,0 +1,31 @@ + 'save_user.php', + 'method' => 'POST' +]); + +$form->load($inputs); +$form->field(type: "text", name: "additional_email", params: [ + 'class' => 'additional_email form-control form-control-dark', + 'label' => 'Дполнительный email', + 'id' => 'additional_email', +]); +$form->render(); + +$form2 = new UserForm([ + 'action' => "save_client.php", + 'method' => 'POST' +]); + +$form2->field(type: "text", name: "user_id", params: [ + 'class' => 'form-control form-control-dark', + 'label' => 'Пользователь', + 'id' => 'user_id', +]); +$form2->render(); \ No newline at end of file diff --git a/views/layouts/main.php b/views/layouts/main.php new file mode 100644 index 0000000..2a64536 --- /dev/null +++ b/views/layouts/main.php @@ -0,0 +1,60 @@ + + + + Form2 + + + + + +
+
+
+ + + + + + + + +
+ +
+ +
+ + +
+
+
+
+
+ +
+ + + \ No newline at end of file