One Final Note: Dots
Now that you have a form action page that will adapt to whatever form values you throw at it, you need to take a moment to look at one situation that often catches PHP programmers by surprise.Listing 10. Adding an image button
Notice that although there's only one image, there are two buttons, or desired outcomes, in the graphic. As a developer, you can tell where the user clicked by examining the x and y coordinates that are returned with the values. In fact, submitting the form as is might create a URL and querystring ending in:
Notice the .x and .y appended to the name of the button. If you were to submit the page and look at the results, however, you'd see:
Notice that the period (.)
has been converted to an underscore (_). This may seem a little odd,
but it's necessary because variable names in PHP can't have periods in
$formbutton.x would be an illegal variable name.
In fact, any periods in form names -- not just those for image buttons
-- are converted to underscores.
In this article, you looked at some of the ways to access information submitted by a user through an HTML or XHTML form. How you handle this information will depend on the version of PHP you're using and whether you can access your form variables as globals. In any case, form values are available as arrays, and you can use the properties of arrays to loop through any available values.