faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

18 of 20 people (90%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

What is the best way to send an 'unknown' number of form fields and access them on the text page?

Feb 28th, 2008 00:02
dman, Jeroen Keppens, John McCaskill, http://www.ttnr.org


<?
// First reset the array storing all values recieved from the form
reset ($HTTP_POST_VARS);   // if form method="post"
reset ($HTTP_GET_VARS);    // if form method="get"
// First way : with "while loop"
while (list($key, $value) = each ($HTTP_POST_VARS)) {
    echo "Key: $key; Value: $value<br>\n";
}
// Second way : with "foreach"
foreach ($HTTP_POST_VARS as $key => $value) {
    echo "Key: $key; Value: $value<br>\n";
}
?>
I hope this answers your question
Jeroen