I’ve created a php page with two forms but I would like to have only one submit button for both forms. the forms have the ids firstform & secondform. I have tried other scripts but they don’t really work.
Here is my code below:
<script language="javascript">
submitForms = function(){
document.getElementById("firstform").submit();
document.getElementById("secondform").submit();
}
</script>
<input type="image" src="images/order-button.png" name="button" value="Submit" onclick="submitForms()"/>
You have SEVERAL issues
input type=image IS a submit button so you are trying to submit something from a non-existing form, likely the same page you are on
when you submit form1, it replaces the current page, if you manage to submit form2 as well, it is VERY likely to interfere with the submission of form1
Here is what you can TRY (plain javascript):
Alternatively AJAX the forms one at a time (assumes jQuery loaded)
DEMO HERE
UPDATE: If you want two form’s content to be submitted to one action, just add the serialises:
PS: The PHP in the demo is just echoing back what you post. There is no special action needed on the server.