More on submitting forms
At the heart of every dynamic website is a way for the user to interact with the data it provides, and one very common way of interacting with with such data is by the use of HTML Forms. Generally (and hopefully obviously), a form is "submitted" when the user activates an HTML input element with the type attribute set to submit. However, most user agents will also submit a form when you give focus to an input element with attribute set to text and hit return. With PHP, the most common way to test if a form has been submitted is to simply test if the $_POST/$_GET array is empty or not, however when using the aforementioned multiple submit button techniques, a problem arises:
- sensible user agents (Gecko based browser, for example) will simply act as though the first submit button had been pressed, and proceed normally.
- MSIE (Internet Exploder?) will submit the form without passing any submit elements in the resulting array, which can cause all kinds of problems if you want to test their validity
The Solution? It is perfectly valid to have multiple input elements with the same name attribute, so simply place a hidden field with the same name/value as your preferred default action. For example:
1 comment November 28th, 2005