Submitting multiple forms using javascript's submit()

Posted on 2006-03-24
Last Modified: 2013-12-12

I have 2 forms on the same page. I use this for the submit buttons:

<INPUT onclick=document.f1.submit(); type=button value="Send f1">
f1 is form name

on the 2nd form:

<INPUT onclick=document.f2.submit(); type=button value="Send f2">
f2 is form name

The problem is in my PHP script. How do I know when the different forms were submitted?
I try
but it doesn't work.

Only if I define the button with type=submit does it work.

Also how do I tell which form was sent?


Question by:tr5
    1 Comment
    LVL 49

    Accepted Solution

    Add an hidden input field in both forms:

    <input type="hidden" name="sourceForm" value="form1" />

    Then use:

    if(isset($_POST['sourceForm']) && $_POST['sourceForm'] == 'form1') {


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    True Type Font Files? 4 46
    Problem to echo 6 29
    generate a dynamic mysql query 2 23
    Php Sql Query 7 19
    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now