Only the logged in user can edit the form. If another user logged in and try to edit the form, he wouldn't able to edit the form until the first user logged out or close the form.
-
add column in the table which will track if the data is being edited. Every time someone open the form for editing or submit the form after finishing you can update the flag column. – Ropali Munshi Dec 30 '19 at 10:51
2 Answers
Probably the easiest way of doing this is to create a column in the db called locked_time
or something.
If a user starts editing, we check the timestamp and if older than X minutes, then we allow the user to edit, and update the timestamp.
To ensure it stays locked if a user is on the same page for a while, you can use JS to send a request to PHP every minute, which will update the timestamp and keep the record locked. Once a user closes the browser, no more updates to the timestamp will occur, and thus the lock will expire and another user can begin editing.
Hope this helps!

- 12,118
- 2
- 21
- 39
If there are multiple forms that needs to be locked if any user has accessed it, I suggest creating a table (for example table_locks
) that have form_id
updated_at
locked
as columns. When a user for example clicks the "edit" link/button for that form, you check if the form is locked (locked == 1), if it is locked you prompt the user that someone else is editing it. If the form is not locked, you set the locked value to 1 until the user posts the new changes or you use the timestamp to add a time/timeout limit.

- 111
- 1
- 3
- 15