looping through post variables?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

looping through post variables?

Post by rsmarsha »

I have a form with a drop down select list for each of the various categories.

I need to somehow loop through the post variables on the next page to show them all, without having to manually enter each variable on the next page. Also some of the variables will not need to be looped to, quantity is one. I want to make the process automated, atm i have an array with the names of the variables entered which is then looped through. Need to loop and be able to use the variable name and value in the next page.

Any ideas? Just need a way to loop through the variables automatically.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

if (!empty($_POST)) {
   foreach ($_POST as $postName => $postValue) {
      echo $postName .'='. $postValue .'<br />';
   }
}
:wink:
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Jcart wrote:

Code: Select all

if (!empty($_POST)) {
   foreach ($_POST as $postName => $postValue) {
      echo $postName .'='. $postValue .'<br />';
   }
}
:wink:
that's right, but he wants to exclude some variables from the loop, so adding an if inside your foreach would enable him to exclude whichever he wants, here is an example to exclude quantity:

Code: Select all

if (!empty($_POST)) {
   foreach ($_POST as $postName => $postValue) {
    if ($postName != "quantity") {
      echo $postName .'='. $postValue .'<br />';
    }
   }
}
i noticed your from leeds, nice, me too :)
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

Thanks. :)

Any jobs going then jay? ;)
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

Got it mostly working. The one problem i'm having is, it shows one from each drop down list which has been posted through, then it's trying to show the others in the lists even though they were not selected. Post must be posting through all the options from each list rather than just the selected option.

EDIT

I tried echo'ing postName so i could see what the other 2 it was trying to post are. They have the names X and Y? Any ideas?

Btw i know it's posting them as it's showing () which are part of my display loop.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

If you view the POST values of a submit button it will give you X and Y, which are the coordinates at which the button was clicked. They're useful for when someone is selecting a point on an image to submit a form, but for the majority of forms, they aren't useful.

Just implement another if statement to avoid your button when showing the values.

Oh, and no, I don't have any jobs going, I'm struggling to get any decent jobs myself!
Post Reply