Is it possible to send form data to a PHP class’ method rather than to a file? Or would I have to use AJAX to do this?
For instance, can I have something like:
<form action="my_obj::form_submit" method="post">...</form>
//rather than
<form action="my_obj.php" method="post">...</form>
I don’t want anyone to be able to access the entire file directly. I don’t see a problem having a single public static method that is available, though, because a single method is easy to “harden” for public use. There is an AJAX function to help me do this, but I think it would be faster to not do that.
Thanks
No, it’s not possible as the client-side code can never know about that kind of server-side implementation detail. As Chuck Vose comments, if that were even possible, it’s a major security liability.
actionattributes on<form>elements, like<a href>, are simply URIs, so you cannot point to some specific part of a PHP code and expect PHP to assemble everything and run it. Again it’s the same client/server side issue.Unless you use some kind of URL routing like many frameworks provide (per webbiedave’s answer), you won’t be able to go any further than a URI pointing to a PHP script in your site.