This commit is contained in:
kali 2024-04-16 17:13:42 +03:00
parent 87deac2576
commit a3faec247e
10 changed files with 42 additions and 419 deletions

View File

@ -1,98 +0,0 @@
<?php
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Extension\SandboxExtension;
use Twig\Markup;
use Twig\Sandbox\SecurityError;
use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;
/* form/resultItem.html.twig */
class __TwigTemplate_94bc2d1f79a7d79af045673fc12da74a extends Template
{
private $source;
private $macros = [];
public function __construct(Environment $env)
{
parent::__construct($env);
$this->source = $this->getSourceContext();
$this->blocks = [
'title' => [$this, 'block_title'],
'content' => [$this, 'block_content'],
];
}
protected function doGetParent(array $context)
{
// line 1
return "layouts/simple.html.twig";
}
protected function doDisplay(array $context, array $blocks = [])
{
$macros = $this->macros;
$this->parent = $this->loadTemplate("layouts/simple.html.twig", "form/resultItem.html.twig", 1);
$this->parent->display($context, array_merge($this->blocks, $blocks));
}
// line 3
public function block_title($context, array $blocks = [])
{
$macros = $this->macros;
echo twig_escape_filter($this->env, ($context["title"] ?? null), "html", null, true);
}
// line 5
public function block_content($context, array $blocks = [])
{
$macros = $this->macros;
// line 6
echo " <h1 class=\"display-4\">";
echo twig_escape_filter($this->env, ($context["title"] ?? null), "html", null, true);
echo "</h1>
";
// line 8
echo twig_escape_filter($this->env, $this->env->getFunction('create_get_action')->getCallable()(), "html", null, true);
echo "
";
}
/**
* @codeCoverageIgnore
*/
public function getTemplateName()
{
return "form/resultItem.html.twig";
}
/**
* @codeCoverageIgnore
*/
public function isTraitable()
{
return false;
}
/**
* @codeCoverageIgnore
*/
public function getDebugInfo()
{
return array ( 64 => 8, 58 => 6, 54 => 5, 47 => 3, 36 => 1,);
}
public function getSourceContext()
{
return new Source("", "form/resultItem.html.twig", "/home/kali/php/untitled/views/form/resultItem.html.twig");
}
}

View File

@ -1,97 +0,0 @@
<?php
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Extension\SandboxExtension;
use Twig\Markup;
use Twig\Sandbox\SecurityError;
use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;
/* form/form.html.twig */
class __TwigTemplate_1782f108c6541d589defb1221fcbfccb extends Template
{
private $source;
private $macros = [];
public function __construct(Environment $env)
{
parent::__construct($env);
$this->source = $this->getSourceContext();
$this->blocks = [
'title' => [$this, 'block_title'],
'content' => [$this, 'block_content'],
];
}
protected function doGetParent(array $context)
{
// line 1
return "layouts/simple.html.twig";
}
protected function doDisplay(array $context, array $blocks = [])
{
$macros = $this->macros;
$this->parent = $this->loadTemplate("layouts/simple.html.twig", "form/form.html.twig", 1);
$this->parent->display($context, array_merge($this->blocks, $blocks));
}
// line 3
public function block_title($context, array $blocks = [])
{
$macros = $this->macros;
echo twig_escape_filter($this->env, ($context["title"] ?? null), "html", null, true);
}
// line 5
public function block_content($context, array $blocks = [])
{
$macros = $this->macros;
// line 6
echo " <h1 class=\"display-4\">";
echo twig_escape_filter($this->env, ($context["title"] ?? null), "html", null, true);
echo "</h1>
";
// line 7
echo twig_escape_filter($this->env, $this->env->getFunction('create_form')->getCallable()(), "html", null, true);
echo "
";
}
/**
* @codeCoverageIgnore
*/
public function getTemplateName()
{
return "form/form.html.twig";
}
/**
* @codeCoverageIgnore
*/
public function isTraitable()
{
return false;
}
/**
* @codeCoverageIgnore
*/
public function getDebugInfo()
{
return array ( 63 => 7, 58 => 6, 54 => 5, 47 => 3, 36 => 1,);
}
public function getSourceContext()
{
return new Source("", "form/form.html.twig", "/home/kali/php/untitled/views/form/form.html.twig");
}
}

View File

@ -1,103 +0,0 @@
<?php
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Extension\SandboxExtension;
use Twig\Markup;
use Twig\Sandbox\SecurityError;
use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;
/* layouts/simple.html.twig */
class __TwigTemplate_e48551b2ca758109aa7de7556ee07a2e extends Template
{
private $source;
private $macros = [];
public function __construct(Environment $env)
{
parent::__construct($env);
$this->source = $this->getSourceContext();
$this->parent = false;
$this->blocks = [
'title' => [$this, 'block_title'],
'content' => [$this, 'block_content'],
];
}
protected function doDisplay(array $context, array $blocks = [])
{
$macros = $this->macros;
// line 1
echo "<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\">
<title>";
// line 5
$this->displayBlock('title', $context, $blocks);
echo " </title>
<link rel=\"stylesheet\" href=\"vendor/twbs/bootstrap/dist/css/bootstrap.css\">
<link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css\" rel=\"stylesheet\"
integrity=\"sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN\" crossorigin=\"anonymous\" />
</head>
<body>
<div class=\"container\">
<div class=\"row\">
<div class=\"col-12\">
";
// line 15
$this->displayBlock('content', $context, $blocks);
// line 16
echo " </div>
</div>
</div>
</body>
</html>";
}
// line 5
public function block_title($context, array $blocks = [])
{
$macros = $this->macros;
}
// line 15
public function block_content($context, array $blocks = [])
{
$macros = $this->macros;
}
/**
* @codeCoverageIgnore
*/
public function getTemplateName()
{
return "layouts/simple.html.twig";
}
/**
* @codeCoverageIgnore
*/
public function getDebugInfo()
{
return array ( 78 => 15, 72 => 5, 60 => 16, 58 => 15, 45 => 5, 39 => 1,);
}
public function getSourceContext()
{
return new Source("", "layouts/simple.html.twig", "/home/kali/php/untitled/views/layouts/simple.html.twig");
}
}

View File

@ -1,102 +0,0 @@
<?php
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Extension\SandboxExtension;
use Twig\Markup;
use Twig\Sandbox\SecurityError;
use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;
/* form/result.html.twig */
class __TwigTemplate_e631c8331e0b3314f0fca4478f143546 extends Template
{
private $source;
private $macros = [];
public function __construct(Environment $env)
{
parent::__construct($env);
$this->source = $this->getSourceContext();
$this->blocks = [
'title' => [$this, 'block_title'],
'content' => [$this, 'block_content'],
];
}
protected function doGetParent(array $context)
{
// line 1
return "layouts/simple.html.twig";
}
protected function doDisplay(array $context, array $blocks = [])
{
$macros = $this->macros;
$this->parent = $this->loadTemplate("layouts/simple.html.twig", "form/result.html.twig", 1);
$this->parent->display($context, array_merge($this->blocks, $blocks));
}
// line 3
public function block_title($context, array $blocks = [])
{
$macros = $this->macros;
echo twig_escape_filter($this->env, ($context["title"] ?? null), "html", null, true);
}
// line 5
public function block_content($context, array $blocks = [])
{
$macros = $this->macros;
// line 6
echo " <h1 class=\"display-4\">";
echo twig_escape_filter($this->env, ($context["title"] ?? null), "html", null, true);
echo "</h1>
";
// line 8
echo twig_escape_filter($this->env, $this->env->getFunction('create_table')->getCallable()(), "html", null, true);
echo "
";
// line 9
echo twig_escape_filter($this->env, $this->env->getFunction('create_pagination')->getCallable()(), "html", null, true);
echo "
";
}
/**
* @codeCoverageIgnore
*/
public function getTemplateName()
{
return "form/result.html.twig";
}
/**
* @codeCoverageIgnore
*/
public function isTraitable()
{
return false;
}
/**
* @codeCoverageIgnore
*/
public function getDebugInfo()
{
return array ( 68 => 9, 64 => 8, 58 => 6, 54 => 5, 47 => 3, 36 => 1,);
}
public function getSourceContext()
{
return new Source("", "form/result.html.twig", "/home/kali/php/untitled/views/form/result.html.twig");
}
}

View File

@ -32,6 +32,7 @@ $router->get("/form-delete/{id}", [\itguild\forms\app\controllers\FormController
$router->get("/form-edit/{id}", [\itguild\forms\app\controllers\FormController::class, "editAction"]); $router->get("/form-edit/{id}", [\itguild\forms\app\controllers\FormController::class, "editAction"]);
$router->get("/admin/create-form", [\itguild\forms\app\controllers\AdminController::class, "createAction"]); $router->get("/admin/create-form", [\itguild\forms\app\controllers\AdminController::class, "createAction"]);
$router->post("/admin/save-form", [\itguild\forms\app\controllers\AdminController::class, "saveForm"]); $router->post("/admin/save-form", [\itguild\forms\app\controllers\AdminController::class, "saveForm"]);
$router->post("/admin/handler", [\itguild\forms\app\controllers\AdminController::class, "ajax"]);
$dispatcher = new Phroute\Phroute\Dispatcher($router->getData()); $dispatcher = new Phroute\Phroute\Dispatcher($router->getData());
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); $response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));

12
public/js/ajax.js Normal file
View File

@ -0,0 +1,12 @@
function ajaxRequest() {
const request = new XMLHttpRequest();
request.open("POST", "handler");
request.addEventListener("load", () => {
const responseText = request.responseText;
const targetElement = document.getElementById("buttonAdd");
targetElement.insertAdjacentHTML("beforebegin", responseText);
});
request.send();
}

View File

@ -7,6 +7,13 @@ use itguild\forms\app\core\BaseController;
use itguild\forms\app\models\FormModel; use itguild\forms\app\models\FormModel;
use itguild\forms\core\cg_view\CgView; use itguild\forms\core\cg_view\CgView;
/**
* @var \itguild\forms\ActiveForm $form ;
*/
use itguild\forms\Form;
use itguild\forms\inputs\TextInput;
use itguild\forms\inputs\TextArea;
class AdminController extends BaseController class AdminController extends BaseController
{ {
@ -31,6 +38,16 @@ class AdminController extends BaseController
echo "Форма сохранена!"; echo "Форма сохранена!";
} }
} }
public function ajax()
{
$form = new ActiveForm();
$form->field(TextInput::class, name: "title", params: [
'class' => "form-control",
'placeholder' => 'Название формы'
])
->setLabel("Название формы")
->render();
}

1
views/admin/ajax.php Normal file
View File

@ -0,0 +1 @@
<?php

View File

@ -15,28 +15,19 @@ use itguild\forms\inputs\TextArea;
]) ])
->setLabel("Название формы") ->setLabel("Название формы")
->render(); ->render();
$form->field(TextArea::class, name: "params", params: [
'class' => "form-control",
'placeholder' => 'Параметры формы' ?>
]) <button style="margin-top:15px" type="button" id="buttonAdd" class="btn btn-primary form-control" onclick="ajaxRequest()">Добавить поле</button>
->setLabel("Параметры формы")
->render();
<?php
$form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ $form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
'class' => "btn btn-primary ", 'class' => "btn btn-primary ",
'value' => 'Отправить', 'value' => 'Отправить',
'typeInput' => 'submit' 'typeInput' => 'submit'
]) ])
->render(); ->render();
$form->endForm();
?> ?>
<script>
$.ajax({
url:'/handler.php',
method: 'post',
dataType: 'html'
data: {element: 'value', abc:'test'},
success: function (data){
console.log(<<Sent successfully: >> + data);
}
});
</script>
<?php $form->endForm(); ?>

View File

@ -9,9 +9,10 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title><?php echo $title ?></title> <title><?php echo $title ?></title>
<link rel="stylesheet" href="vendor/twbs/bootstrap/dist/css/bootstrap.css"> <link rel="stylesheet" href="/vendor/twbs/bootstrap/dist/css/bootstrap.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous" /> integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous" />
<script src="/public/js/ajax.js"></script>
</head> </head>
<body> <body>
<div class="container"> <div class="container">