Users updating their own data from the frontend

Hey there!

I’m trying to implement a small form to allow frontend users of a page to update part of their own user data.

<?php return function ($kirby) {
    $error = false;
    $success =false;
    $message = "";

    if ($kirby->request()->is('POST') && get('update')) {

        //I've left out all the validation here to keep the example brief.

        try {
            'name' => get('name'),
            'email'     => get('email')
            $success = true;
        } catch(Exception $e) {
            $error = true;
            $message = "User could not be updated!";
    return [
        'error' => $error,
        'message' => $message,
        'success' => $success
<form action="" method="post" enctype="multipart/form-data">
    <input class="p-text green" type="text" id="name" name="name" placeholder="Name" value="<?= $kirby->user()->name() ?>">
    <input class="p-text green" type="email" id="email" name="email" placeholder="Email" value="<?= $kirby->user()->email() ?>">
    <input class="p-button green clickable" type="submit" name="update" value="Submit changes">

<?php if($error): ?>
    <span class="p-alert red"><?= $message ?></span>
<?php endif; ?>
<?phpif($success): ?>
    <span class="p-alert green">User data was updated!</span>
<?php endif; ?>

The odd thing is that the function is reporting success, yet no data is being updated. This doesn’t seem to be an issue with data retrieval from the form, as the data passes validation in the controller.

I’m I assuming correctly that users can update their own data without impersonating a super user? I guess if this were a permission issue, I wouldn’t be getting a success report, right?

Thank you for your time!

With the update method, you can only change additional user data that is stored in the user.txt file. To change the name and the email, you would have to use the $user->changeName() and $user->changeEmail() methods.

Ah, gotcha - looks like I didn’t read the reference closely enough!
Thanks for the quick clarification!