By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,520 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,520 IT Pros & Developers. It's quick & easy.

2 Forms on 1 Page. How to separate Post Variables?

P: 7
I have 2 forms on one page. I have hidden variables in each form, with separate names, that contain values. The user decides which form to submit on. Only 1 form will be processed.

Now my problem is, when I read the Post Variables from the server side with PHP.

Expand|Select|Wrap|Line Numbers
  2. foreach($_POST as $name => $value) {
  3.       print "$name : $value<br>";
  4. }
That code will output the hidden variables from both forms, rather than just the form the user submitted on respectively.

Expand|Select|Wrap|Line Numbers
  1. <form name = 'form0' method = 'POST' action='add.php'>
  2.       <input type = 'hidden' name='hItem0' value = 'test0'>;
  3.       <input type = 'submit' value = 'Add0'>
  4. </form>
  6. <form name = 'form1' method = 'POST' action='add.php'>
  7.       <input type = 'hidden' name='hItem1' value = 'test1'>;
  8.       <input type = 'submit' value = 'Add1'>
  9. </form>

The output on add.php is test0 and test1, despite which form the user submitted on.

Someone care to shed some light?
Sep 21 '08 #1
Share this Question
Share on Google+
4 Replies

Expert 5K+
P: 7,435
The html is correct, and functions correctly, so I can only assume there is something wrong on the PHP side. You need to ask on that board.
Sep 21 '08 #2

P: 7
Well the PHP side is the server side. There can't be anything wrong there because the HTML submits the post variables to the PHP side.

The PHP side doesn't create post they are obviously getting sent over.
Sep 21 '08 #3

P: 7
Well you are correct about the HTML being right. I stupidly, forgot to close the tag on the form. I put </form rather than </form>. I typed it correctly, of course, above.

It amazes me how many problems I run into due to stupid mistakes like this lol. I always look for a logical answer as to why something isn't work but it always winds up being the most unexpected mistake.

Thanks for your help.
Sep 21 '08 #4

Expert 5K+
P: 7,435
Don't forget. I am never, ever, ever wrong.
Sep 22 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.