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.
looping through post variables?
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
if (!empty($_POST)) {
foreach ($_POST as $postName => $postValue) {
echo $postName .'='. $postValue .'<br />';
}
}- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
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:Jcart wrote:Code: Select all
if (!empty($_POST)) { foreach ($_POST as $postName => $postValue) { echo $postName .'='. $postValue .'<br />'; } }
Code: Select all
if (!empty($_POST)) {
foreach ($_POST as $postName => $postValue) {
if ($postName != "quantity") {
echo $postName .'='. $postValue .'<br />';
}
}
}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.
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.
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
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!
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!