Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6972445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:58:07+00:00 2026-05-27T16:58:07+00:00

I have included an additional Submit button within my form which I am going

  • 0

I have included an additional Submit button within my form which I am going to use like so.

  1. User selects item
  2. User hits “Add another item” Submit button on form.
  3. Form POSTS to itself and reloads the page so user can add another item
  4. Once user has added several items the user hits “Finished” Submit button.
  5. The form posts to another file with all the accumulated items.

I have a uneasy feeling that this might not be achievable with PHP/HTML alone and that I might have to use some Javascript to modify the form action before the form starts to POST data?

Thoughts and ideas?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:58:08+00:00Added an answer on May 27, 2026 at 4:58 pm

    You can use JavaScript to modify the form based on which button is clicked, or you can check server side (i.e. using PHP) which button was clicked and act accordingly.

    A submit-button is a form-input just like any other, i.e. you can give it a name and a value, which you can check for server side.

    On client side (i.e. using JavaScript) you would bind a handler to the button’s click-event, modify the form’s action-attribute and submit it to the new address.

    Here’s a client side example:

    <!doctype html>
    <html>
        <head>
            <title>Form submit test</title>
        </head>
        <body>
            <form action="baz.html" method="post">
                <input id="bar" type="submit" class="button" value="bar.html" name="" />
                <input id="foo" type="submit" class="button" value="foo.html" name="" />
            </form>
    
            <script>
                // Find the two buttons from the DOM and assign them to separate variables
                var barBtn = document.getElementById('bar'),
                    fooBtn = document.getElementById('foo');
    
                // Click-handler for the buttons. 
                // NB! For this code to work as intended, it needs to run 
                // in the context of the button, otherwise, the this-keyword 
                // will not resolve correctly and this will result in an error
                // NB2! This code also requires that a button's value will be
                // the desired action handler. Usually you would probably not
                // do this, but use the button's name/value to lookup the 
                // correct form action.
                function modifyAction(e) {
                    this.form.action = this.value;
                }
    
                // Bind an event handler to an object
                // NB! This is not code you should use in production
                function bindEvent(target, event, callback) {
                    if (target.addEventListener) {
                        target.addEventListener(event, callback, false);
                    } else if (target.attachEvent) {
                        target.attachEvent('on' + event, callback);
                    }
                }
    
                // Delegate creates a wrapping closure which binds the 
                // original function's context to an object, i.e. ensuring
                // the this-keyword always refers to the same object when
                // the returned function is invoked. 
                function delegate(context, method) {
                    return function () {
                        return method.apply(context, arguments);
                    }
                }
    
                // Bind the click-event of the barBtb, and handle it
                // with the modifyAction-function bound to the barBtn.
                // I.e. run the modifyAction function, with the this-keyword
                // bound to barBtn
                bindEvent(barBtn, 'click', delegate(barBtn, modifyAction));
    
                // Same as above for fooBtn
                bindEvent(fooBtn, 'click', delegate(fooBtn, modifyAction));
            </script>
        </body>
    </html>
    

    Just for sake of completeness, here’s a jQuery-example of the same:

    <form action="baz.html" method="post">
        <input id="bar" type="submit" class="button" value="bar.html" name="" />
        <input id="foo" type="submit" class="button" value="foo.html" name="" />
    </form>
    
    <script>
    // Jquery event-handlers are automatically bound to
    // the element selected, so using "this" is safe
    function modifyAction(e) {
        this.form.action = this.value;
    }
    
    // Bind the click-event on all input with type=submit
    $("input[type=submit]").click(modifyAction);
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot get a form to submit additional fields that have been cloned. When
I have included Zend_Form_Element_Hash into a form multiplecheckbox form. I have jQuery set to
I have a simple ATL Service in which I have included the following statement.
The code compiles fine and I have included the vssapi.lib in the additional dependencies
I have a table in a DB (Postgres based), which acts like a superclass
I have a form where a user submits the description of an object (including
I have a common HTML header file which I use in several PHP files.
I have VS 2008 Professional Edition. After the installation (which included SQL Server 2008),
Sometime back while designing something that included user management, I was required to have
I have a project that has the following line in the additional includes section:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.