I have three separate buttons in html. Each button is representing one form. I want to know how to execute a different php action=“phpfile.php” for each button press.
If you want to submit the form data to a php script depending on which button was pressed then you don’t need 3 functions. You can do it with just 1 function. In the form’s onsubmit event handler just change the value of the form’s action attribute to the correct value for the pressed button before submitting the form.
You’re not making sense because of course you can have as many forms as you like, each with their own submit button to submit only the form the pressed button is in.
I had this problem once too, I originally solved it in JavaScript, but thats not really the right thing to do, either make multiple form one for each button with hidden fields (not recommended) or just when you submit to php1, include php2 and 3 and put them in classes or functions or whatever and check the value of the button to see which one was clicked and just run whichever function or class corresponds to that value.
Oh and like i said above, it is possible to use three different submit forms, just use hidden fields for the values you need.