[UPHPU] Posting a form -- test cases

Jon Jensen jon at jenseng.com
Thu Feb 24 10:28:47 MST 2005


> <quote who="Wade Preston Shearer">
> > That sounds like a fluke or a browser issue. Keying 
> "enter/return" is 
> > the same as clicking "submit."
> 
> Wade's comment is incorrect. The 'submit' $_POST entry will 
> only be set if the button named 'submit' is actually clicked. 
> This is the designated behavior for HTTP. What I usually do 
> is use a hidden input field like
> this:
> 
>   <input type="hidden" name="submit" value="submit" />
> 
> Sometimes, I'll name it "action" and set its value to 
> something indicative of the action to preform, like 
> "create_new_user" or "login", then inspect the contents of 
> $_POST['action'] in the receiving script.

You are both correct ;) It simply depends on the browser.

In Mozilla and Opera, keying enter in a text field is the same as clicking
the first submit button in the form. There is an actual click event on the
button, and it gets submitted along with the form.

In IE this is not the case.

I don't know about Konqueror or Safari.

Here's an example that tests both javascript and what gets sent to the
server:

http://jenseng.com/submittest.php

Type something in the text field and hit enter. You will get an alert if a
click event occurred on the button. The form is then submitted, the when the
page refreshes you see exactly what is in the $_POST array.

The behavior is the same regardless the number of submit buttons in the form
-- in Opera and Mozilla, the first one is always "clicked"

So you really can't ever rely on the submit button being pressed. Either use
Dave's approach (a hidden element), or my preferred method is to have
distinct scripts to handle each form in my site/app.

Jon




More information about the UPHPU mailing list