1

I have a frontend form that updates a single entry and sets the users field to the current user:

<form method="post" accept-charset="UTF-8">
    {{ csrfInput() }}
    {{ actionInput('entries/save-entry') }}
    {{ redirectInput('') }}
    {{ hiddenInput('sectionId', '1') }}
    {{ hiddenInput('entryId', entry.id) }}
    {{ hiddenInput('enabled', '1') }}
    
    <input type="text" name="fields[myFieldHandle][]" value="{{ currentUser.id }}" hidden>
    <button type="submit">Save</button>
    
</form>

Let's assume that the users field is empty and user1 submits the form. The users field will be set to user1. If user2 submits the form after that, the users field will be set to user2.

User2 should not be able to update the users field, because its value is already set to user1.

I don't really know how to achieve this since you cannot simply add a user to a users field without overwriting existing values. I could disable the form for user2 in the frontend but that doesn't solve the problem.

1 Answer 1

1

As far as I'm aware, there is no way to explicitly disable a custom field once it has a value.

You could prevent data for that field from being submitted on the front end by only providing the input for myFieldHandle if it does not have a value:

{% if not entry.myFieldHandle.exists() %}
  <input type="text" name="fields[myFieldHandle][]" value="{{ currentUser.id }}" hidden>
{% endif %}

If myFieldHandle already has a user associated with it, the field will not be provided on the front-end, thus the field cannot be changed.

1
  • Thanks for your reply. I thought about that as well but I need to be 100% sure the field cannot be overwritten. Even if 2 users submit the form at the same time without reloading the website in between.
    – jlg1807
    Commented Oct 14, 2022 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.