Page 1 of 1

looping through post variables?

Posted: Thu Dec 15, 2005 4:20 am
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.

Posted: Thu Dec 15, 2005 5:39 am
by John Cartwright

Code: Select all

if (!empty($_POST)) {
   foreach ($_POST as $postName => $postValue) {
      echo $postName .'='. $postValue .'<br />';
   }
}
:wink:

Posted: Thu Dec 15, 2005 7:49 am
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 :)

Posted: Fri Dec 16, 2005 3:05 am
by rsmarsha
Thanks. :)

Any jobs going then jay? ;)

Posted: Fri Dec 16, 2005 3:27 am
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.

Posted: Fri Dec 16, 2005 5:44 am
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!