i have a website that has multiple forms, after the user submits one of those forms, it goes to a handler page that has all the handling stuff for all forms,either it enters the form data to the database, or sends it to a class that gets elements from the database and displays it dynamically, and more stuff, the thing is that the handler page has too many if statements that decide what form is submitted and what to do with it, and there are a lot of classes that does a lot of stuff, i know code with a lot of if statements is not good, how can i order the logic of my website, is there a design pattern i can use? is my way okay? i'm gonna show you an example of the logic without the actual code so you can understand better.
the handler page
if(isset($_POST['Registration']))
{
//send to database
}
if(isset($_POST['login']))
{
//header to a page
}
if(isset($_POST['show-menu']))
{
//send to a class that displays data from database dynamically
}
if(isset($_POST['enter-dish']))
{
$obj = new DishValidation(// constructer parameters );
$obj->validateDish();
if (validateDish()==true){
//send to database
}
}
and way other stuff
what's also bothering me is that some if statements send to the database directly from the handler, some if statements use class to validate something, or do something else, i feel like everything on the website should be either in a class, why is the sending data to the database is directly from the handler page and other stuff are using the classes.
what can i do to fix this? i need a cleaner code with better logic and handeling.
Aucun commentaire:
Enregistrer un commentaire