1

I have jQuery to submit 'N' number of forms. Now I need to read the POST values based on the number of components. Can anyone suggest code to read those all POST values? especially i want to read approve1 , approve2 ... values

Note: when i click submit all these different form values are submitted to submit.php page

My Form:

<form name="f1" action="submit.php" method=POST>
<input type="hidden" name="approve1" value="93545" />
<input type="submit" value="Submit/>
</form>

<form name="f2" action="submit.php" method=POST>
<input type="hidden" name="approve2" value="93545" />
<input type="submit" value="Submit/>
</form>

.....

<input type="button" value="Submit All"/>

jQuery:

$(function() {
    $("#submitAll").click(function(ev) {
        ev.preventDefault();
        var newForm = $("<form action='submit.php' method='POST'></form>");
        $("form input[type='hidden']").each(function(i, e) {
            newForm.append(
                $("<input type='hidden' />")
                    .attr("name", e.name)
                    .attr("value", e.value)
            );
        });
        $(document.body).append(newForm);
        newForm.submit();
    });
});

foreach($_POST as $name => $value) posts only last form value i.e approve2 value in this example

2
  • 1
    Does the request made from JS really sends approve1 and approve2? If so, you can access them via $_POST['approve1'] and $_POST['approve2'] Commented Feb 27, 2014 at 19:16
  • @MichalBrašna: Yes! I Can access it not a problem. But my problem is it can send N approve POST values. How should it find it ? Commented Feb 28, 2014 at 3:51

1 Answer 1

1
foreach($_POST as $name => $value) {
  // Here you have access to parameter names and their values
  echo "<p>name is $name and value is $value</p>";
}
Sign up to request clarification or add additional context in comments.

8 Comments

i did a test. its not working.. There are 10 form values posted but this code is returning only th last form values. foreach($_POST as $name => $value) { echo $i."<br>";$i=$i+1; } outputs only the last form values are returned
@logan What is $i? I cannot see it in your code, or in what I suggested.
I just put it for testing purpose. to print how many values are posted. consider only 2 forms are there in my question, for it , simply it returns approve2 POST value only others are not coming. Where are i could see all POST values in Chrome -> develoer -> network area
@logan if you want to see all posted names and their values, use the updated code. If you don't see what you expect, it simply means you do not post it.
updated code ? where is it ? And more over, i said, the JQuery submitting 2 post values from different forms. i could see it in developer section of chrome page. but when i use foreach($_POST as $name => $value) it shows only last form value
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.