.
Developer Spot - Web Development Tutorials
arrowDeverloper Spot  Tutorials  PHP  Using HTML Forms With PHP 
 
Development Tutorials
ASP
CGI & Perl
CSS
HTML
Java
JavaScript
Linux
PHP
XML




More Resources
Web Hosting Articles
Web Development News
PHP Manual
Web Hosting Directory
Budget Web Hosting Linux Web Hosting Small Business Hosting
Windows Web Hosting Reseller Web Hosting Web Hosting Articles

Using HTML Forms With PHP

By Nicholas Chase
2004-01-09
Reader Rating: 5 out of 5
Bookmark Print Version
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.

In some cases, rather than using a submit button, a designer opts for a graphic button, as shown in Figure 2 and the code shown in Listing 10.

Listing 10. Adding an image button



...
<tr>
<td valign="top">Crew species: </td>
<td>
<select name="crew[]" multiple="multiple">

<option value="xebrax">Xebrax</option>
<option value="snertal">Snertal</option>
<option value="gosny">Gosny</option>
</select>

</td>
</tr>
<tr>
<td colspan="2" align="center">

<input type="image" src="button.gif" name="formbutton"/>
</td>
</tr>
</table>
...

Figure 2. Graphic button on form

Adding a graphic 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:


...snertal&crew%5B%5D=gosny&formbutton.x=37&formbutton.y=14


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:


ship = Midnight Runner
tripdate = 12-15-2433
exploration = yes
crew = snertal
crew = gosny

formbutton_x = 37

formbutton_y = 14


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 them, so $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.


Article Pages:
Access Single and Multiple Form Values
The HTML Form
The Old Way: Accessing Global Variables
Accessing Form Value Collections
One Name, Multiple Values
The Amazing Disappearing Checkboxes
Getting All Form Values
One Final Note: Dots
Summary
Resources

First published by IBM developerWorks


 Rate this article:   Poor          Excellent 


If you found this article interesting, you may want to read these as well:

» Protecting your PHP and HTML Source Code

» Publishing Newsletters Using PHP & MySQL - 4

» Publishing Newsletters Using PHP & MySQL - 3

» Publishing Newsletter Using PHP & MySQL - 2

» Publishing Newsletters Using PHP & MySQL

» Unix Webserver Crontab Basics



 
Development Tutorials: CGI & Perl - CSS - HTML - Java - JavaScript - Linux - PHP - XML
More Resources: Web Hosting Articles - Web Development News - PHP Manual