Using HTML Forms With PHP
By Nicholas Chase2004-01-09
Getting All Form Values
Fortunately, because $HTTP_GET_VARS and its ilk are simply hash tables, you can use some of the properties of arrays to manipulate them. For example, you can use the array_keys() function to get a list of all of the potential value names:
Listing 8. Getting a list of form value names
|
In this case, you actually combine several techniques. First, retrieve an array of form field names and call it $form_fields. The $form_fields array is just a typical array, so you can use the sizeof() function to determine the number of potential keys, and loop through each one. For each one, you retrieve the name of the field and then use that name to get the actual value. The result is a Web page that reads:
|
Notice two important things here. First, the contact field didn't return at all, as expected. Second, the crew value (which is, incidentally, named crew and not crew[], as you might expect) is an array, and not a value. To actually retrieve all values, you'll need to detect any arrays using the is_array() function and handle them accordingly:
Listing 9. Accounting for arrays
|
The result is all of the data that was actually submitted:
|
Tutorial pages:
|
First published by IBM developerWorks
|
|||||||||
You might also want to check these out:
|
Leave a Comment on "Using HTML Forms With PHP"
You must be logged in to post a comment.
Link to This Tutorial Page!

