feat: improved validation of personal data

This commit is contained in:
Björn Fromme
2025-04-11 08:29:06 +02:00
parent 011fe9c5c4
commit 9c1aa60782
5 changed files with 53 additions and 27 deletions
+16 -6
View File
@@ -2,13 +2,23 @@
namespace App\BusProNet\Model; namespace App\BusProNet\Model;
use Symfony\Component\Validator\Constraints as Assert;
class Address class Address
{ {
public ?string $street = null; #[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
public ?string $postCode = null; public ?string $street = '';
public ?string $city = null;
public ?string $district = null; #[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
public ?string $country = null; public ?string $postCode = '';
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
public ?string $city = '';
public ?string $district = '';
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
public ?string $country = '';
public function toPayload(): array public function toPayload(): array
{ {
@@ -20,4 +30,4 @@ class Address
'land' => $this->country, 'land' => $this->country,
]; ];
} }
} }
+12 -4
View File
@@ -2,11 +2,19 @@
namespace App\BusProNet\Model; namespace App\BusProNet\Model;
use Symfony\Component\Validator\Constraints as Assert;
class Communication class Communication
{ {
public ?string $phone = null; public ?string $phone = '';
public ?string $mobile = null;
public ?string $email = null; #[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
public ?string $mobile = '';
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
#[Assert\Email(message: 'Bitte eine gültige Adresse angeben', mode: 'strict', groups: ['personal_data'])]
public ?string $email = '';
public bool $newsletter = false; public bool $newsletter = false;
public function toPayload(): array public function toPayload(): array
@@ -18,4 +26,4 @@ class Communication
'newsletter' => $this->newsletter ? 'True' : 'False', 'newsletter' => $this->newsletter ? 'True' : 'False',
]; ];
} }
} }
+23 -17
View File
@@ -9,29 +9,35 @@ class PersonalData
public ?int $addressId = null; public ?int $addressId = null;
public ?int $personId = null; public ?int $personId = null;
public bool $mutable = false; public bool $mutable = false;
public ?string $status = null; public ?string $status = '';
#[Assert\NotBlank(message: 'Bitte angeben')] #[Assert\NotBlank(message: 'Bitte angeben', groups: ['Default', 'personal_data'])]
public ?string $name = null; public ?string $name = '';
#[Assert\NotBlank(message: 'Bitte angeben')] #[Assert\NotBlank(message: 'Bitte angeben', groups: ['Default', 'personal_data'])]
public ?string $firstName = null; public ?string $firstName = '';
public ?string $salutation = null; public ?string $salutation = '';
public ?string $title = null; public ?string $title = '';
public ?string $gender = null; public ?string $gender = '';
public ?string $nationality = null; public ?string $nationality = '';
public ?string $height = null; public ?string $height = '';
public ?string $shoeSize = null; public ?string $shoeSize = '';
public ?string $weight = null; public ?string $weight = '';
public ?\DateTimeImmutable $dateOfBirth = null; public ?\DateTimeImmutable $dateOfBirth = null;
public ?string $remarks = null; public ?string $remarks = '';
#[Assert\Valid()] #[Assert\Valid(groups: ['personal_data'])]
public ?Address $address = null; public Address $address;
#[Assert\Valid()] #[Assert\Valid(groups: ['personal_data'])]
public ?Communication $communication = null; public Communication $communication;
public function __construct()
{
$this->address = new Address();
$this->communication = new Communication();
}
public function toPayload(): array public function toPayload(): array
{ {
@@ -55,6 +55,7 @@ class PersonalDataController extends AbstractController
$personalDataForm = $this->createForm(PersonalDataType::class, $personalData, [ $personalDataForm = $this->createForm(PersonalDataType::class, $personalData, [
'attr' => ['novalidate' => 'novalidate'], 'attr' => ['novalidate' => 'novalidate'],
'validation_groups' => ['personal_data'],
]); ]);
$personalDataForm->handleRequest($request); $personalDataForm->handleRequest($request);
+1
View File
@@ -38,6 +38,7 @@ class PersonalDataType extends AbstractType
]) ])
->add('phone', TextType::class, [ ->add('phone', TextType::class, [
'label' => 'Telefon', 'label' => 'Telefon',
'required' => false,
'property_path' => 'communication.phone', 'property_path' => 'communication.phone',
]) ])
->add('mobile', TextType::class, [ ->add('mobile', TextType::class, [