How to make one form to add and edit at the same time?

There is a form. When editing the data it is sent to the page with the handler /edit, and when you add to the page handler /add. At the moment resolved at JS - inserted the desired action="/edit"or action="/add". But still I would like to solve it in php.

And the second point - preloading field values when using the edit form. I would like to find a solution based on these two things - bootstrapping and action on different URLs.
July 9th 19 at 10:15
2 answers
July 9th 19 at 10:17
If the form is to substitute the data for editing, you can make a hidden field with the record ID, and it is the competent organization of storage certainly is. When sending data, the receiving script can look if there's id, then edit if missing or zero, then add
July 9th 19 at 10:19
To add to the form hidden field _method:
<input type="hidden" name="_method" value="POST">
And then in the form handler to perform the desired action. Typically, methods such appointments.
  1. GET — resource acquisition
  2. POST — create a resource
  3. PUT — update a resource
  4. DELETE — delete resource

Find more questions by tags PHP