hello, i have encountered a strange phenomenon.
i have a flag button, onclick userid gets written into a field of an ‘exercise’ page ‘flag_$color’ like so:
$userId = $_POST['userId'];
$exerciseId = $_POST['exerciseId'];
$color = strtolower($_POST['color']);
// Get the Kirby CMS page object based on the exercise ID
$page = page($exerciseId);
if ($page) {
$fieldName = 'flag_' . strtolower($color);
$existingFlags = $page->$fieldName();
// Debug statement
error_log('User ID: ' . $userId);
error_log('Exercise ID: ' . $exerciseId);
error_log('Color: ' . $color);
error_log('Existing Flags: ' . $existingFlags);
// Check if the user ID is already present in the field
if (strpos($existingFlags, $userId) === false) { // Use strict comparison to ensure correct behavior
// Update the field by appending the user ID with a comma
$existingFlags = trim($existingFlags);
if ($existingFlags !== '') {
$updatedFlags = $existingFlags . ', ' . $userId;
} else {
$updatedFlags = $userId;
}
$page->update([$fieldName => $updatedFlags]);
// Debug statement
error_log('Field Name: ' . $fieldName);
error_log('Updated Flags: ' . $updatedFlags);
this works great.
now the problem is that after the ‘flag_green’ field was correctly updated another field named ‘schueler’ gets completely reset!? (the schueler field w checkboxes has the purpose to select students to which the exercise is displayed.)
before:
----
Flag-green:
----
Schueler: Lee, Ole, Christoph, Felix, Colin, Olli
----
after:
----
Flag-green: sO4SaRWe
----
Schueler:
----
now the really strange part is:
that only happens when logged in as role student! tested w other students acc aswell.
as admin, everything works and field ‘schueler’ stays intact.
nowhere in the whole flag-part i have a role conditional. nowhere i write to the field ‘schueler’…this is the only page->update() function i put in.
the blueprint:
schueler:
type: checkboxes
options:
type: query
query: kirby.users.filterBy('role', 'student').filterBy('teacher', kirby.user.name).sortBy('name', 'asc')
text: "{{ item.name }}"
value: "{{ item.name }}"
flag_green:
label: Green Flags
type: text
flag_red:
label: Red Flags
type: text
from the error logs
[Tue Jun 13 14:03:20.628094 2023] [php:notice] [pid 6328:tid 1888] [client ::1:50558] User ID: sO4SaRWe, referer: http://localhost/ue/rich/?student=Lee
[Tue Jun 13 14:03:20.628094 2023] [php:notice] [pid 6328:tid 1888] [client ::1:50558] Exercise ID: rich/categories/basics/asymp, referer: http://localhost/ue/rich/?student=Lee
[Tue Jun 13 14:03:20.628094 2023] [php:notice] [pid 6328:tid 1888] [client ::1:50558] Color: green, referer: http://localhost/ue/rich/?student=Lee
[Tue Jun 13 14:03:20.628094 2023] [php:notice] [pid 6328:tid 1888] [client ::1:50558] Existing Flags: , referer: http://localhost/ue/rich/?student=Lee
[Tue Jun 13 14:03:20.728271 2023] [php:notice] [pid 6328:tid 1888] [client ::1:50558] Field Name: flag_green, referer: http://localhost/ue/rich/?student=Lee
[Tue Jun 13 14:03:20.728271 2023] [php:notice] [pid 6328:tid 1888] [client ::1:50558] Updated Flags: sO4SaRWe, referer: http://localhost/ue/rich/?student=Lee
i really have no clue where to investigate further. any help very much appreciated!
regards
fusi