You cannot place code in the action attribute, that's simply not how HTML works.
<form action="index.php">
<input type="hidden" name="do" value="dotest">
You will need a router in your application that dispatches the tasks. In this case the "do" query parameter will dictate what to do. The code can be a big switch statement (not recommended), or you can store the actions in separate files/classes/class methods. You can look up the code directly (file_exists
/method_exists
/autoloading...) or you can decouple the lookup and do some kind of pre-registration and store the actions in a dictionary(array
).
I would recommend checking some PHP frameworks too get some ideas. There are some very clever routers and controller abstractions out there. It's going to be better than you can come up with, especially if you're unexperienced.
Note: there's nothing wrong with lots of small files - just try to use a single entry point for your web application.