diff --git a/public/js/ajax.js b/public/js/ajax.js
index 3a0b523..035730a 100644
--- a/public/js/ajax.js
+++ b/public/js/ajax.js
@@ -15,10 +15,12 @@ function ajaxRequest() {
}
function getValueSelect(){
var selectValue = document.getElementById("selectID").value
- var inputTags = document.getElementsByTagName('input');
- var inputCount = inputTags.length - 3;
- var request = new XMLHttpRequest()
- request.open("GET", "/admin/set-value-select?value=" + selectValue + "&count=" + inputCount, true)
+ var request = new XMLHttpRequest();
+ let button = document.getElementById("buttonAdd");
+ let count = parseInt(button.dataset.count) + 1;
+ button.dataset.count = count;
+ console.log(count);
+ request.open("GET", "/admin/set-value-select?value=" + selectValue + "&count=" + count, true)
request.addEventListener("load", () => {
var responseText = request.responseText;
var targetElement = document.getElementById("buttonAdd");
diff --git a/src/ActiveForm.php b/src/ActiveForm.php
index dcb17da..e508ae0 100755
--- a/src/ActiveForm.php
+++ b/src/ActiveForm.php
@@ -4,6 +4,7 @@ namespace itguild\forms;
use itguild\forms\builders\ButtonBuilder;
use itguild\forms\builders\CheckBoxBuilder;
+use itguild\forms\builders\HiddenBuilder;
use itguild\forms\builders\RadioButtonBuilder;
use itguild\forms\builders\SelectBuilder;
use itguild\forms\builders\TextAreaBuilder;
@@ -12,6 +13,7 @@ use itguild\forms\debug\Debug;
use itguild\forms\inputs\BaseInput;
use itguild\forms\inputs\Button;
use itguild\forms\inputs\Checkbox;
+use itguild\forms\inputs\Hidden;
use itguild\forms\inputs\RadioButton;
use itguild\forms\inputs\Select;
use itguild\forms\inputs\TextArea;
@@ -61,6 +63,9 @@ class ActiveForm
elseif ($class === RadioButton::class){
$this->fieldObject = RadioButtonBuilder::build($name, $params);
}
+ elseif ($class === Hidden::class){
+ $this->fieldObject = HiddenBuilder::build($name, $params);
+ }
else {
$this->fieldObject = new $class($name, $params);
}
diff --git a/src/app/controllers/AdminController.php b/src/app/controllers/AdminController.php
index 31fd953..fbb1cb5 100644
--- a/src/app/controllers/AdminController.php
+++ b/src/app/controllers/AdminController.php
@@ -5,6 +5,7 @@ namespace itguild\forms\app\controllers;
use Illuminate\Database\Events\DatabaseBusy;
use itguild\forms\ActiveForm;
use itguild\forms\app\core\BaseController;
+use itguild\forms\app\models\FormInputModel;
use itguild\forms\app\models\FormModel;
use itguild\forms\core\cg_view\CgView;
@@ -31,12 +32,25 @@ class AdminController extends BaseController
}
public function saveFormAction(): void
{
+
$title = $_POST["title"];
- $params = $_POST["params"];
- if (isset($title) and isset($params)) {
- $form = FormModel::Create(['title' => $title, 'status' => FormModel::STATUS_ACTIVE, 'params' => $params]);
- echo "Форма сохранена!";
- }
+ $perPage = $_POST['perPage'];
+ $inputs = $_POST["InputForm"];
+ $inputArray = [];
+ foreach ($inputs as $input){
+ $form = FormInputModel::Create(['form_id' => 42, 'input_type_id' => $input['type'], 'label' => $input['name'], 'name' => 'adsads', 'params' => "adsasd"]);
+ Debug::prn($form);
+
+ }
+
+ $resultArray = ['meta' => ['perpage' => $perPage]];
+
+ Debug::prn(json_encode($resultArray, true));
+
+ //if (isset($title) and isset($params)) {
+ // $form = FormModel::Create(['title' => $title, 'status' => FormModel::STATUS_ACTIVE, 'params' => json_encode($resultArray, true)]);
+ // echo "Форма сохранена!";
+ //}//
}
public function getFormAddFieldsAction(): void
{
@@ -46,7 +60,6 @@ class AdminController extends BaseController
{
$selectValue = $_GET["value"];
$countInput = $_GET["count"];
- Debug::prn($countInput);
$form = new ActiveForm();
$fields = [
@@ -64,9 +77,10 @@ class AdminController extends BaseController
throw new FieldTypeNotFound($selectValue);
}
- $this->cgView->render("/admin/field_type/$viewName.php", ['form' => new ActiveForm()]);
+ $this->cgView->render("/admin/field_type/$viewName.php", ['form' => new ActiveForm(), 'count' => $countInput]);
}
+
}
\ No newline at end of file
diff --git a/views/admin/field_type/_button.php b/views/admin/field_type/_button.php
index 98d513f..124fda4 100644
--- a/views/admin/field_type/_button.php
+++ b/views/admin/field_type/_button.php
@@ -9,6 +9,8 @@
use itguild\forms\inputs\Checkbox;
use itguild\forms\inputs\TextInput;
-$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control",
- 'placeholder' => "Наименование"])->setLabel("Наименование (например \"Телефон\")")->render();
-$form->field(Checkbox::class, name: "RequiredInput", params:[])->setLabel("Обязательное")->render();
+
+$form->field(TextInput::class, name: "InputForm[$count][name]", params: ['class' => "form-control",
+ 'placeholder' => "Наименование поля"])->setLabel("Наименование поля (например \"Телефон\")")->render();
+$form->field(Checkbox::class, name: "InputForm[$count][required]", params:['value' => '1'])->setLabel("Обязательное")->render();
+$form->field(\itguild\forms\inputs\Hidden::class, name: "InputForm[$count][type]", params: ['value' => '5'])->render();
diff --git a/views/admin/field_type/_checkBox.php b/views/admin/field_type/_checkBox.php
index 9abd729..51d4f8c 100644
--- a/views/admin/field_type/_checkBox.php
+++ b/views/admin/field_type/_checkBox.php
@@ -3,12 +3,14 @@
/**
*
* @var \itguild\forms\ActiveForm $form
+ * @var integer $count
*
*/
use itguild\forms\inputs\Checkbox;
use itguild\forms\inputs\TextInput;
-$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control",
+$form->field(TextInput::class, name: "InputForm[$count][name]", params: ['class' => "form-control",
'placeholder' => "Наименование"])->setLabel("Наименование (например \"Телефон\")")->render();
-$form->field(Checkbox::class, name: "RequiredInput", params:[])->setLabel("Обязательное")->render();
\ No newline at end of file
+$form->field(Checkbox::class, name: "InputForm[$count][required]", params:['value' => '1'])->setLabel("Обязательное")->render();
+$form->field(\itguild\forms\inputs\Hidden::class, name: "InputForm[$count][type]", params: ['value' => '1'])->render();
\ No newline at end of file
diff --git a/views/admin/field_type/_radioButton.php b/views/admin/field_type/_radioButton.php
index 40787de..1469f24 100644
--- a/views/admin/field_type/_radioButton.php
+++ b/views/admin/field_type/_radioButton.php
@@ -9,6 +9,7 @@
use itguild\forms\inputs\Checkbox;
use itguild\forms\inputs\TextInput;
-$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control",
+$form->field(TextInput::class, name: "InputForm[$count][name]", params: ['class' => "form-control",
'placeholder' => "Наименование"])->setLabel("Наименование (например \"Телефон\")")->render();
-$form->field(Checkbox::class, name: "RequiredInput", params:[])->setLabel("Обязательное")->render();
\ No newline at end of file
+$form->field(Checkbox::class, name: "InputForm[$count][required]", params:['value' => '1'])->setLabel("Обязательное")->render();
+$form->field(\itguild\forms\inputs\Hidden::class, name: "InputForm[$count][type]", params: ['value' => '4'])->render();
\ No newline at end of file
diff --git a/views/admin/field_type/_select.php b/views/admin/field_type/_select.php
index 68c43fa..b84d475 100644
--- a/views/admin/field_type/_select.php
+++ b/views/admin/field_type/_select.php
@@ -10,13 +10,11 @@ use itguild\forms\inputs\Checkbox;
use itguild\forms\inputs\TextArea;
use itguild\forms\inputs\TextInput;
-$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control",
- 'placeholder' => "Наименование поля"])
- ->setLabel("Наименование поля (например \"Телефон\")")
- ->render();
-$form->field(TextArea::class, name: "OptionsInput", params: ['class' => "form-control"])
+
+$form->field(TextInput::class, name: "InputForm[$count][name]", params: ['class' => "form-control",
+ 'placeholder' => "Наименование"])->setLabel("Наименование (например \"Телефон\")")->render();
+$form->field(TextArea::class, name: "InputForm[$count][options]", params: ['class' => "form-control"])
->setLabel("Опции выпадающего списка")
->render();
-$form->field(Checkbox::class, name: "RequiredInput", params:[])
- ->setLabel("Обязательное поле")
- ->render();
\ No newline at end of file
+$form->field(Checkbox::class, name: "InputForm[$count][required]", params:['value' => '1'])->setLabel("Обязательное")->render();
+$form->field(\itguild\forms\inputs\Hidden::class, name: "InputForm[$count][type]", params: ['value' => '6'])->render();
\ No newline at end of file
diff --git a/views/admin/field_type/_text_input.php b/views/admin/field_type/_text_input.php
index 8f327c4..4895371 100644
--- a/views/admin/field_type/_text_input.php
+++ b/views/admin/field_type/_text_input.php
@@ -3,14 +3,16 @@
/**
*
* @var \itguild\forms\ActiveForm $form
+ * @var integer $count
*
*/
use itguild\forms\inputs\Checkbox;
use itguild\forms\inputs\TextInput;
-$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control",
+$form->field(TextInput::class, name: "InputForm[$count][name]", params: ['class' => "form-control",
'placeholder' => "Наименование поля"])->setLabel("Наименование поля (например \"Телефон\")")->render();
-$form->field(TextInput::class, name: "PlaceholderInput", params: ['class' => "form-control",
+$form->field(TextInput::class, name: "InputForm[$count][placeholder]", params: ['class' => "form-control",
'placeholder' => 'Placeholder'])->setLabel("Placeholder")->render();
-$form->field(Checkbox::class, name: "RequiredInput", params:[])->setLabel("Обязательное поле")->render();
\ No newline at end of file
+$form->field(Checkbox::class, name: "InputForm[$count][required]", params:['value' => '1'])->setLabel("Обязательное")->render();
+$form->field(\itguild\forms\inputs\Hidden::class, name: "InputForm[$count][type]", params: ['value' => '2'])->render();
\ No newline at end of file
diff --git a/views/admin/field_type/_textarea.php b/views/admin/field_type/_textarea.php
index a72cd78..3bb1cd8 100644
--- a/views/admin/field_type/_textarea.php
+++ b/views/admin/field_type/_textarea.php
@@ -9,8 +9,9 @@
use itguild\forms\inputs\Checkbox;
use itguild\forms\inputs\TextInput;
-$form->field(TextInput::class, name: "NameInput", params: ['class' => "form-control",
+$form->field(TextInput::class, name: "InputForm[$count][name]", params: ['class' => "form-control",
'placeholder' => "Наименование поля"])->setLabel("Наименование поля (например \"Телефон\")")->render();
-$form->field(TextInput::class, name: "PlaceholderInput", params: ['class' => "form-control",
+$form->field(TextInput::class, name: "InputForm[$count][placeholder]", params: ['class' => "form-control",
'placeholder' => 'Placeholder'])->setLabel("Placeholder")->render();
-$form->field(Checkbox::class, name: "RequiredInput", params:[])->setLabel("Обязательное поле")->render();
\ No newline at end of file
+$form->field(Checkbox::class, name: "InputForm[$count][required]", params:['value' => '1'])->setLabel("Обязательное")->render();
+$form->field(\itguild\forms\inputs\Hidden::class, name: "InputForm[$count][type]", params: ['value' => '3'])->render();
\ No newline at end of file
diff --git a/views/admin/index.php b/views/admin/index.php
index 3f038df..a59512d 100644
--- a/views/admin/index.php
+++ b/views/admin/index.php
@@ -24,12 +24,7 @@ $form->field(TextInput::class, name: "perPage", params: [
])
->setLabel("Количество выводимых записей на страницу")
->render();
-$form->field(TextArea::class, name: "paramsForm", params: [
- 'class' => "form-control",
- 'placeholder' => 'Параметры'
-])
- ->setLabel("Параметры")
- ->render();
+
$form->field(\itguild\forms\inputs\Select::class, name: "inputType", params: [
'class' => "form-control-sm",
'id' => "selectID",
@@ -39,7 +34,7 @@ $form->field(\itguild\forms\inputs\Select::class, name: "inputType", params: [
->setLabel("Добавить поле")
->render();
?>
-
+