Die vul ik met gegevens, die ik vervolgens in een json object gooi.
class Customer implements JsonSerializable {
public $firstName;
public $middleName;
public $lastName;
public $email;
public $phoneMobile;
public $gender;
public $zipcode;
public $city;
public $address;
public $houseNumber;
public $houseNumberExtension;
public $birthDate;
public $iban;
public $setAVG;
public function __construct($data){
$this->firstName = $data['fname'];
$this->middleName = $data['prefix'];
$this->lastName = $data['lname'];
$this->email = $data['email'];
$this->phoneMobile = $data['phone'];
$this->gender = $data['gender'];
$this->zipcode = $data['zipcode'];
$this->city = $data['place'];
$this->address = $data['street'];
$this->houseNumber = $data['houseNumber'];
$this->houseNumberExtension = $data['extension'];
$this->birthDate = $data['birthdate'];
$this->iban = strtoupper(str_replace(" ", "", $data['iban']));
$this->setAVG = $data['avg'];
}
public function jsonSerialize() {
return [
"FirstName"=> $this->firstName,
"MiddleName"=> $this->middleName,
"LastName"=> $this->lastName,
"Email"=> $this->email,
"PhoneMobile"=> $this->phoneMobile,
"Gender"=> $this->gender,
"Zipcode" => $this->zipcode,
"City"=> $this->city,
"Address" => $this->address,
"HouseNumber" => $this->houseNumber,
"HouseNumberExtension" => $this->houseNumberExtension,
"BirthDate"=> $this->birthDate,
"IBAN"=> $this->iban,
"SetAVG"=> $this->setAVG,
"Country"=> 'Nederland',
"Language"=> 'nl_NL',
"UseValidation" => true,
"IsValidated" => true,
];
}
}
Nu komt er iets nieuws. Als iemand minder jarig is (dit word met JS gedaan) dan komt er een extra email veld bij in het formulier voor ouder/voogd. Op het moment dus dat `$_POST['EmailCaregiver']` bestaat/aanwezig is, wil ik die meegeven in het customer object.
Wat is een handige manier om dit voor elkaar te krijgen?