I’m trying to create a simple check-in application where the user clicks a button and it updates a structure field entry with checkedin = “Yes” or empty.
staffers:
label: Staffers
type: structure
style: table
entry: >
{{name}}<br />{{email}}
fields:
name:
label: Full Name
type: text
email:
label: Email
type: email
checkedIn:
label: Checked In
type: hidden
Here’s the code from the AJAX call:
<?php
if(kirby()->request()->ajax()) {
$userAnswer = kirby()->request()->query()->name();
// Get Staff Page
$staffPage = $pages->findBy('uid', 'staff');
foreach($staffPage->staffers()->yaml() as $staff) {
if($staff['name'] = $userAnswer and $staff['checkedin'] == '') {
$this[] = ['name' => $staff['name'], 'email' => $staff['email'], 'checkedin' => 'Yes'];
$fieldData = yaml::encode($this);
$staffPage->update(['staffers' => $fieldData]);
};
if($staff['name'] = $userAnswer and $staff['checkedin'] == 'Yes') {
$this[] = ['name' => $staff['name'], 'email' => $staff['email'], 'checkedin' => ''];
$fieldData = yaml::encode($this);
$staffPage->update(['staffers' => $fieldData ]);
};
}
}
else {
header::status('404');
}
Using this method, it updates all of the entries in the structure, which makes sense. I’m wanting to just update the single entry (which I’m sure is pretty easy) but I’m not sure how to go about it.
Any ideas?