feat: improved validation of personal data
This commit is contained in:
@@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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, [
|
||||||
|
|||||||
Reference in New Issue
Block a user