add barebones form

This commit is contained in:
Constantin Simonis 2025-01-23 19:59:20 +01:00
parent 138d030b5a
commit 541fd2d40d
Signed by: csimonis
GPG Key ID: 758DD9C506603183
4 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,24 @@
<?php
namespace App\Controller;
use App\DataObjects\TicketData;
use App\Form\TicketForm;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
final class TicketController extends AbstractController
{
#[Route('/ticket', name: 'app_ticket')]
public function index(Request $request): Response
{
$data = new TicketData();
$form = $this->createForm(TicketForm::class, $data)->handleRequest($request);
return $this->render('ticket/index.html.twig', [
'form' => $form->createView(),
]);
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace App\DataObjects;
class TicketData
{
public function __construct(
public string $email = '',
public string $notes = '',
public string $firstname = '',
public string $lastname = '',
public string $phone = '',
)
{
}
}

21
src/Form/TicketForm.php Normal file
View File

@ -0,0 +1,21 @@
<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
class TicketForm extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('email', EmailType::class)
->add('notes', TextareaType::class)
->add('firstname', TextType::class)
->add('lastname', TextType::class)
->add('phone', TextType::class);
}
}

View File

@ -0,0 +1,6 @@
{% extends 'base.html.twig' %}
{% block title %}Bestellen{% endblock %}
{% block body %}
{% endblock %}