The given method will work assuming the user is using a form to input data. I'm not aware of a way to log the changes when a user just straight up changes the data in the table.
If that's not a problem, then yeah, you can just put that code in the form where the user inputs the data and it'll work out.