jQuery Form Submission Does Not Include Button

Posted on 2011-10-05
Last Modified: 2012-05-12

Is it possible to add a whole new input value to $_POST using script? Say within the script that handles a dialogue requiring confirmation, after form submission. I need to create something to identify what button on the form was clicked as the button value is not included in the $_POST when jQuery submits the form/document.


I have a form with mutiple buttons. Clicking will open a dialogue then when clicking accept button within the dialogue only then is POST done. Problem is when jQuery does post document using submit() the buttons value is not included and I always work with this to decide what processing needs to be done.

How do I get around this?

I could use this approach which changes the action, I would append a variable to the current url but I would really like to work from $_POST.
// prevent form submission, display dialogue box instead
            $('form#testform_id').attr({action: "submittedthree"});

Open in new window

This is my dialogue which makes use of submit(), that is where I thought changes could possibly be made per dialogue box to submit more data...
            autoOpen: false,
            modal: true,
            width: 800,
            resizable: true,
            buttons: {
                "Submit": function() {
                    document.<?php echo $multibutton_formname; ?>.submit();
                "Cancel": function() {

Open in new window

I'm basically asking if there are other ways to do this.
Question by:Ryan Bayne
    LVL 81

    Accepted Solution

    You may use an hidden field :
    - ID is hiddenField
    - Name is hiddenField

    so you get the button number/name/ref with : $_POST["hiddenField"]

    // prevent form submission, display dialogue box instead
                if( $("#hiddenField").length == 0 ) $("<input type='hidden' name='hiddenField' id='hiddenField' value='submittedthree' />").appendTo("form#testform_id"); else $("#hiddenField").val("submittedthree");

    Open in new window

    LVL 2

    Author Comment

    by:Ryan Bayne
    Great so we can probably do a lot to a form this way then.

    I was about to mess around with the action and URL approach but in Wordpress I like to try and reduce the number of values passed this way.

    Thanks once again

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
    Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
    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…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now