473,799 Members | 3,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Foreach element in $_POST?

Hey

Is there a way to go through each element in the $_POST supervariable?

I'm making a page with dynamic forms, so I don't know for sure how many
$_POST variables there will be (the number of textboxes, radio buttons,
etc changes).

How can I either count them or do a foreach loop to do this?

Thanks

iw****@gmail.co m

Dec 6 '05 #1
4 4620
IW****@gmail.co m wrote:
Hey

Is there a way to go through each element in the $_POST supervariable?

I'm making a page with dynamic forms, so I don't know for sure how many
$_POST variables there will be (the number of textboxes, radio buttons,
etc changes).

How can I either count them or do a foreach loop to do this?

Thanks

iw****@gmail.co m


iwp506,

Easy, just treat $_POST as an array and use foreach.
http://www.php.net/manual/en/control...es.foreach.php

Don't forget to make the post values safe before using them if they were
input by the users...

Carl.
Dec 6 '05 #2

Carl wrote:
IW****@gmail.co m wrote:
Hey

Is there a way to go through each element in the $_POST supervariable?

I'm making a page with dynamic forms, so I don't know for sure how many
$_POST variables there will be (the number of textboxes, radio buttons,
etc changes).

How can I either count them or do a foreach loop to do this?

Thanks

iw****@gmail.co m


iwp506,

Easy, just treat $_POST as an array and use foreach.
http://www.php.net/manual/en/control...es.foreach.php

Don't forget to make the post values safe before using them if they were
input by the users...

Carl.


Ok, thanks

Dec 6 '05 #3
Following on from Carl's message. . .

Easy, just treat $_POST as an array and use foreach.
http://www.php.net/manual/en/control...es.foreach.php

Don't forget to make the post values safe before using them if they were
input by the users...

Further don't forget that elements of $_POST may be arrays in their own
right. eg Checkboxes. Here is a snippet of code as illustration
#---------------------------------------------------------------------
function POSTget($VarNam e,$tidy=TRUE){
# read POSTed value from HTTP_POST_VARS
# Normally we'll tidy up the input to remove leading and trailing spaces
and control chars
# but this can be overridden.
#---------------------------------------------------------------------
if (isset($_POST[$VarName])){
$rv = $_POST[$VarName];
if(!is_array($r v)){
if ($tidy) {$rv = TidyInput($rv); }
}
}else{
$rv='';
}
return $rv;
}

--
PETER FOX Not the same since the porcelain business went down the pan
pe******@eminen t.demon.co.uk.n ot.this.bit.no. html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.dem on.co.uk>
Dec 7 '05 #4
fun with forms... iterate_form() not only spits out the values, but
will give you the $var = $_POST['var'] code for the receiving page...
have fun

function iterate_form()
{
echo "<b>Values: </b><br>";
foreach($_POST as $key => $value)
{
echo $key . " = " . $value . "<br>";
}
echo "<br><br><b>Hap py Coding:</b><br>";
foreach($_POST as $key => $value)
{
echo "$". $key . " = \$_POST['". $key . "'];<br>";
}
build_back_form ();
exit;
}

function build_back_form ()
{
echo "<form name='error' method='post' action='".
$_SERVER['HTTP_REFERER'] ."'>\n";
foreach ($_POST as $key => $value)
{
echo "<input type='hidden' name='" . $key . "' value='" .
$value . "'>\n";
}
echo "<input type='submit' name='submit' value='Go
Back'></form>\n";
}

Dec 8 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2731
by: Blaine HIlton | last post by:
I've been trying for 2 days now to solve this problem, which should be pretty simple, but it is turning off to not be as simple. I am trying to pull data out from a form that was POSTed on a previous page. The code that I have that works is below: <?php for ($i = 2; $i <= $stoped; $i++) { echo '<tr>' .'<td>Step '."$i".'</td>'
32
6525
by: Joe Rattz | last post by:
Hmmm, I wrote the following code. I want an array of bools and I want to intialize them to false. bool bits = new bool; foreach(bool bit in bits) { bit = false; } The compiler complains on the "bit = false;" stating that bit is read-only.
8
39652
by: Gopal Krish | last post by:
Any sample code that uses foreach statement to walkthrough a two dimensional array? My requirement is to process data in only one dimension (say column 0 in each row of the array) Example menulinks = "My Home"; menulinks = "MyHome.aspx"; menulinks = "Credit"; menulinks = "Credit.aspx";
9
7752
by: Anthony Bouch | last post by:
Everything I know about looping structures says to be careful about expressions that need to be evaluated again and again for each test/increment of a loop. I came across this piece of code the other day and stopped to think for a minute about whether it was right or not. foreach (XmlNode node in doc.SelectNodes("/root/map/");) { //Do something }
4
2249
by: Jack E Leonard | last post by:
I'm looping through the keys and values of a form submission using foreach($_POST as $key => $value) echo "$key = $value<br>"; No problems there. All works as expected. But seveal of the values are arrays and the echo comes out like: subjectone = Array subjecttwo = Array
9
4053
by: news.microsoft.com | last post by:
I am looping through an iteration and I would like to test the next item but if its not the one that I want how do I put it back so that when my foreach continues it is in the next iteration? Bill
4
4564
by: mab464 | last post by:
I have this code on my WAMP server running on my XP machine if ( isset( $_POST ) ) { for($i=0; $i<count($_POST);$i++) { if ($ans != NULL ) $ans .= ", " . $_POST ; // Not the first element so append a comma
14
3354
by: rashgang | last post by:
i have dynamically created checkbox which will like yahoo mail if check box selected it will highlight a row but deleteall function is not working plz chek it function doDeleteAll($objArray){ foreach($objArray as $strkey=>$strValue) { $strDeleteId = $strValue; doDelete($strDeleteId);
21
2819
by: rashgang | last post by:
no check box selected when i gave delete all link the error is coming <?php include "includes/connection.php"; include "includes/Functions_category.php"; include "includes/functions_db.php"; $Strtitle="Category Management (Category Listing)";
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10228
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.