Ruben, I just wanted to chime in and maybe help you grasp an important distinction in the server/client, PHP/JS paradigm, if I may.
Every bit of code on your site has to run someplace. There are two possibilities for that location:
Server-side - this means that the code runs on the server, before the page is ever sent to the user
Client-side - this means that the code runs in the browser, on the end-user’s computer (after the page has been generated by the server and loaded by the browser)
Understanding this distinction and wrapping your head around what code runs on the server and what runs in the browser is crucial. It gave me trouble when I was first figuring this stuff out, too
In your original example, that doesn’t work because
do_stuff() is executed before the page is loaded in the browser (it’s executed server side), while the
action attribute specifies the location to which the form should be submitted. Instead, that location (URL) should be a PHP script that handles the request and can call
do_stuff after the form is submitted (that’s the solution iGhost gave you).
Anyway, I just think that’s an important distinction to grasp, and it’ll go a long way toward solving these types of problems for you in the future. Hope that helps clarify things for you - it’s an “Ah ha!” moment for many developers