views:

92

answers:

5

I have a PHP-generated page which is displaying some data about a set of films. The page is updated using POST. The form only shows films starting with a particular letter. I want to present a set of clickable options at the top of the screen, each of which is a letter. So if you click on "B" it submits the form and re-draws the page showing only films that start with B. (I know, Ajax would be a better way to do this, but I'm trying to get something done quickly).

Anyway, I know I can do this by having each link be a Javascript call which sets the value of a hidden field and then submits the form, or I could do it by having each letter be a button which has a particular value and submits the form directly, but neither of those strikes me as particularly elegant. Is there a standard way to do this? Am I missing something really obvious?

Thanks,

Ben

+4  A: 

You can always create a number of submit buttons and give each a different name. Then you test to see which submit was pressed based on what is included in the POST array.

Please note that you can use the image input type in place of the submit input type so that you can substitute your own image, etc for your button.

Noah Goodrich
+1  A: 

I think you pretty much cover the options you have. I generally see it done with javascript and hrefs because people don't like to style real buttons.

carson
A: 

You don't actually need to submit the form as you are not really using it.

Why not just a set of hyperlinks B

James Anderson
but then how would I set variables that I needed to pass in to the PHP script? I could do this by adding them on to the URL of each link, but then my script would need to check $_GET as well as $_POST, which feels wrong, somehow...
Ben
A: 

Use several different submit buttons, like this:

<input type="submit" name="letter" value="A" />
<input type="submit" name="letter" value="B" />
<input type="submit" name="letter" value="C" />
...
Piskvor
+1  A: 

Be aware that Internet Explorer (6/7?) doesn't POST a variable with the name of the button on an <input type="image"> - it only posts variables with name_x and name_y with the coordinates of where on the button was clicked.