Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

jQuery Form Submission Does Not Include Button

Hello

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.

More...

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
        $("#button_id3").click(function(e){
            e.preventDefault();
            $('form#testform_id').attr({action: "submittedthree"});
            $("#divid3").dialog('open');
        });

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...
 
$("#divid1").dialog({
            autoOpen: false,
            modal: true,
            width: 800,
            resizable: true,
            buttons: {
                "Submit": function() {
                    document.<?php echo $multibutton_formname; ?>.submit();
                },
                "Cancel": function() {
                    $(this).dialog("close");
                }
            }
        });

Open in new window


I'm basically asking if there are other ways to do this.
0
Ryan Bayne
Asked:
Ryan Bayne
1 Solution
 
leakim971PluritechnicianCommented:
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
        $("#button_id3").click(function(e){
            e.preventDefault();
            if( $("#hiddenField").length == 0 ) $("<input type='hidden' name='hiddenField' id='hiddenField' value='submittedthree' />").appendTo("form#testform_id"); else $("#hiddenField").val("submittedthree");
            $("#divid3").dialog('open');
        });

Open in new window

0
 
Ryan BayneWordPress DeveloperAuthor Commented:
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
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now