0

here is the sample code.

<form id="form1" name="form1" action="phpPage.php" method="POST">
  <!--5 diff values in form1 . . . -->
  <input id="b1" onclick="functionOne();">
</form>
<form id="form2" name="form2" action="phpPage.php" method="POST">
  <!-- 5 diff values in form2 . . . -->
  <input id="b2" onclick="functionTwo();">
</form>

i have up to 8 forms.

The problem is when I click the button b5, after all the validation checks have performed, I want it so it sends all values from form1-form5. I have collected the values in JS function (functionFive();) through jQuery. How can I send these values to the phpPage.php ?

Remembering that we have fired the onclick event on b5 and, as the result, the functionFive has been called for validation checks. How do I send the values from here to php page?

4
  • Do all these forms have the same input names? (.e.g form1 has foo and form2 has foo, too? Commented Jan 10, 2013 at 20:04
  • Why do you have multiple forms? Commented Jan 10, 2013 at 20:12
  • @Brad , they have different input names and values as well. Commented Jan 10, 2013 at 20:17
  • @BlakePlumb, i have such a page where user can either add 1 item detail or 2 items detail or upto 8 items detail. so for each item, i have 1 form. If it selects 7 items, obviously i have to fetch the values of the previous 6 items detail. i get them in JS function, but could not push it to php page. Commented Jan 10, 2013 at 20:19

2 Answers 2

4

The answer is to use ONE FORM that encompasses all the values.

3
  • this would be worst case for me, i have developed the whole application using multiple forms :( Commented Jan 10, 2013 at 20:25
  • 1
    You could write some JavaScript to collect all of the values and submit them into a hidden form, but in the long run that may not be the best way. Commented Jan 10, 2013 at 20:30
  • +1) atleast your comment should be enuff for him to accept this answer. But all values in one form would be the better way to do it Commented Jan 10, 2013 at 20:37
0

Have you tried ajax?

var formData = {
    firstName: 'Dennis',
    lastName: 'Martinez'    
};

$.ajax({
    type: 'post',
    url: 'SOMEFILE.php',
    data: formData,
    success: function(e) {
        alert('success!');
    },
    error: function(e) {
        alert('there was an error!');
    }
});
1
  • I would really go with @Diodeus answer, that is the proper way to do a form. If you really are using the above method to accomplish this please read the ajax documentation api.jquery.com/jQuery.ajax. Commented Jan 10, 2013 at 20:11

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.