In PHP, Are there any patterns people use to submit forms? A form submission best practices.. etc.
Example, I am trying to achieve a CRUD operation. Initially I have been using a same function for handling form-display and form-submission
class Somecontroller extends Controller {
function form1_add() {
// if submit exist save it in database
// else
// display the form
}
function form1_edit() {
// if submit exist save it in database
// else
// display the same form
}
}
What I do not like.. about this practice is, the login to check if there is a submit or whether it is brand new form is in the same function.
I have thought about making two different functions
form1_add() and form1_add_submit()
to handle these operations. But other issues appear for example, on unsuccessful validation, I would have to call form1_add()
from form1_add_submit()
again to display those validation errors.
What other practices do people use for this kind of operation? Are there any specific patterns for these?