Multiple forms in single submit button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhing
    New Member
    • Oct 2006
    • 43

    Multiple forms in single submit button

    Hi, please help me.
    I have a few forms and I need send there forms by one submit input.
    They have the same form action and almost the same fields. It is like a referral page.

    for example
    [code=html]
    <form>
    <input type="text" value="1" name="id" id="id" />
    </form>

    <form>
    <input type="text" value="2" name="id" id="id" />
    </form>

    <form>
    <input type="text" value="3" name="id" id="id" />
    </form>
    [/code]
    i need to send it all at once..

    i have a javascript function that during onclick event it will submit all the forms
    [code=javascript]
    function submitAll(){
    document.form1. submit();
    document.form2. submit();
    document.form3. submit();
    document.form4. submit();
    }
    [/code]

    ..That is the function but it will only send the last form (form4)

    Any ideas regarding this is a big help for me..

    Thnx
    Last edited by Atli; Nov 6 '07, 10:47 PM. Reason: Added [code] tags.
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    Hi,

    any particular reason for using javascript?
    Can't you just do this using html-forms?

    Cheers

    Originally posted by bhing
    Hi, please help me.
    I have a few forms and I need send there forms by one submit input.
    They have the same form action and almost the same fields. It is like a referral page.

    for example
    [code=html]
    <form>
    <input type="text" value="1" name="id" id="id" />
    </form>

    <form>
    <input type="text" value="2" name="id" id="id" />
    </form>

    <form>
    <input type="text" value="3" name="id" id="id" />
    </form>
    [/code]
    i need to send it all at once..

    i have a javascript function that during onclick event it will submit all the forms
    [code=javascript]
    function submitAll(){
    document.form1. submit();
    document.form2. submit();
    document.form3. submit();
    document.form4. submit();
    }
    [/code]

    ..That is the function but it will only send the last form (form4)

    Any ideas regarding this is a big help for me..

    Thnx

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi.

      Please enclose your posted code in [code] tags (See How to Ask a Question).

      This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

      Please use [code] tags in future.

      Moderator

      Comment

      • bhing
        New Member
        • Oct 2006
        • 43

        #4
        Im sorry for not following guidelines..
        Here are my codes:

        [Code=html]


        <form name="form1" action="action. php">
        <input type="text" value="" name="email" id="id" />
        </form>

        <form name="form2" action="action. php">
        <input type="text" value="2" name="email" id="id" />
        </form>

        <form name="form3" action="action. php">
        <input type="text" value="3" name="email" id="id" />
        </form>

        <input type=image onclick="submit All();" />

        [/code]

        i need to send it all at once..

        i have a javascript function that during onclick event it will submit all the forms
        [Code=javascript]


        function submitAll(){
        document.form1. submit();
        document.form2. submit();
        document.form3. submit();
        }
        [/code]


        ..That is the function but it will only send the last form (form4)

        During submit of the forms...It should submit to the email entered by the user...

        But the problem is only the last form is submitted...
        Last edited by Atli; Nov 7 '07, 03:14 PM. Reason: Fixed [code] tags.

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Why have them all seperate?

          [code=html]
          <form name="form" action="action. php">
          <input type="text" value="1" name="email1" id="id1" />

          <input type="text" value="2" name="email2" id="id2" />

          <input type="text" value="3" name="email3" id="id3" />

          <input type="submit" value="submit" name="submit" />
          </form>
          [/code]
          Surely that makes more sense?

          Comment

          • bhing
            New Member
            • Oct 2006
            • 43

            #6
            yes i have to separate them since they have the same name..

            not like in your example that it has email1, email2, and email3...

            in my case they have the same field name.. only email.

            Comment

            • Atli
              Recognized Expert Expert
              • Nov 2006
              • 5062

              #7
              Hi.

              You could try something like this:
              [code=php]
              <?php
              if(isset($_POST['var'])) {
              echo "<pre>";
              print_r($_POST['var']);
              echo "</pre>";
              }
              ?>

              <form action="?" method="POST">
              <input type="text" name="var[]" value="1" /><br />
              <input type="text" name="var[]" value="2" /><br />
              <input type="text" name="var[]" value="3" /><br />
              <input type="text" name="var[]" value="4" /><br />
              <input type="text" name="var[]" value="5" /><br />
              <input type="submit" />
              </form>
              [/code]

              Which would print something like:
              Code:
              Array
              (
                  [0] => 1
                  [1] => 2
                  [2] => 3
                  [3] => 4
                  [4] => 5
              )

              Comment

              • bhing
                New Member
                • Oct 2006
                • 43

                #8
                ok i will try.. but my question is, how to receive it...

                i have firstname,lastn ame,age, email field..

                they are in one form the one that you suggested above..

                if the posted form fields are submitted to the database.. i will do a loop to populate it in the database?

                Comment

                • Atli
                  Recognized Expert Expert
                  • Nov 2006
                  • 5062

                  #9
                  Consider this:
                  [code=php]
                  <pre>
                  <?php
                  if(isset($_POST['var'])) {
                  foreach($_POST['var'] as $_k => $_v) {
                  echo "var #{$_k} = {$_v} \n"
                  }
                  }
                  ?>
                  </pre>

                  <form action="?" method="POST">
                  <input type="text" name="var[]" value="1" /><br />
                  <input type="text" name="var[]" value="2" /><br />
                  <input type="text" name="var[]" value="3" /><br />
                  <input type="text" name="var[]" value="4" /><br />
                  <input type="text" name="var[]" value="5" /><br />
                  <input type="submit" />
                  </form>
                  [/code]

                  You could replace the echo call in the PHP code with a SQL query, or whatever you use to populate your database.

                  Comment

                  • bhing
                    New Member
                    • Oct 2006
                    • 43

                    #10
                    ok..

                    thanks much..

                    its very helpful..

                    i got the idea already..

                    tnx again

                    Comment

                    Working...