feat: improved validation of personal data
This commit is contained in:
@@ -2,13 +2,23 @@
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class Address
|
||||
{
|
||||
public ?string $street = null;
|
||||
public ?string $postCode = null;
|
||||
public ?string $city = null;
|
||||
public ?string $district = null;
|
||||
public ?string $country = null;
|
||||
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
|
||||
public ?string $street = '';
|
||||
|
||||
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
|
||||
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
|
||||
{
|
||||
@@ -20,4 +30,4 @@ class Address
|
||||
'land' => $this->country,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,19 @@
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class Communication
|
||||
{
|
||||
public ?string $phone = null;
|
||||
public ?string $mobile = null;
|
||||
public ?string $email = null;
|
||||
public ?string $phone = '';
|
||||
|
||||
#[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 function toPayload(): array
|
||||
@@ -18,4 +26,4 @@ class Communication
|
||||
'newsletter' => $this->newsletter ? 'True' : 'False',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,29 +9,35 @@ class PersonalData
|
||||
public ?int $addressId = null;
|
||||
public ?int $personId = null;
|
||||
public bool $mutable = false;
|
||||
public ?string $status = null;
|
||||
public ?string $status = '';
|
||||
|
||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
||||
public ?string $name = null;
|
||||
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['Default', 'personal_data'])]
|
||||
public ?string $name = '';
|
||||
|
||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
||||
public ?string $firstName = null;
|
||||
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['Default', 'personal_data'])]
|
||||
public ?string $firstName = '';
|
||||
|
||||
public ?string $salutation = null;
|
||||
public ?string $title = null;
|
||||
public ?string $gender = null;
|
||||
public ?string $nationality = null;
|
||||
public ?string $height = null;
|
||||
public ?string $shoeSize = null;
|
||||
public ?string $weight = null;
|
||||
public ?string $salutation = '';
|
||||
public ?string $title = '';
|
||||
public ?string $gender = '';
|
||||
public ?string $nationality = '';
|
||||
public ?string $height = '';
|
||||
public ?string $shoeSize = '';
|
||||
public ?string $weight = '';
|
||||
public ?\DateTimeImmutable $dateOfBirth = null;
|
||||
public ?string $remarks = null;
|
||||
public ?string $remarks = '';
|
||||
|
||||
#[Assert\Valid()]
|
||||
public ?Address $address = null;
|
||||
#[Assert\Valid(groups: ['personal_data'])]
|
||||
public Address $address;
|
||||
|
||||
#[Assert\Valid()]
|
||||
public ?Communication $communication = null;
|
||||
#[Assert\Valid(groups: ['personal_data'])]
|
||||
public Communication $communication;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->address = new Address();
|
||||
$this->communication = new Communication();
|
||||
}
|
||||
|
||||
public function toPayload(): array
|
||||
{
|
||||
|
||||
@@ -55,6 +55,7 @@ class PersonalDataController extends AbstractController
|
||||
|
||||
$personalDataForm = $this->createForm(PersonalDataType::class, $personalData, [
|
||||
'attr' => ['novalidate' => 'novalidate'],
|
||||
'validation_groups' => ['personal_data'],
|
||||
]);
|
||||
$personalDataForm->handleRequest($request);
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ class PersonalDataType extends AbstractType
|
||||
])
|
||||
->add('phone', TextType::class, [
|
||||
'label' => 'Telefon',
|
||||
'required' => false,
|
||||
'property_path' => 'communication.phone',
|
||||
])
|
||||
->add('mobile', TextType::class, [
|
||||
|
||||
Reference in New Issue
Block a user