Detect cancel on form <input type="cancel"

My form contains

<fieldset id=“choices”>
<input type=“submit” name=“save” value=“Save” />
<input type=“reset” name=“reset” value=“Reset” />
<input type=“cancel” name=“cancel” value=“Cancel” />
</fieldset> <!-- choices –>

The submit and reset work as expected.

Interestingly, the submit and reset come up as buttons, but the cancel comes up as a box in Firefox/3.6.3 and IE 8.0.

More important, how do I detect (and redirect) when user clicks the “cancel”?



(Searched the archives – must not be using correct keywords)

If you’re using PHP:

if (isset($_POST['cancel']))

Thank you for your prompt response.

Only the type=“submit” invokes the php.

I can, of course, change the type=“cancel” to type=“submit” and check in my .php as you suggest. But thought there might be a detectable way to distinguish between the type=“reset” and the type=“cancel” without invoking (and complicating) the .php module.

There is no such HTML as <input type=“cancel”>

The only way you could set up a cancel button would be to either use a submit button and pass a different value to the server saying to cancel OR to use <input type=“button”> with the cancel functionality attached using JavaScript.

You know…there is zero need for a reset button. It is an accident wating to happen. Furthor more, why must the user hit “Cancel” to cancel? Could they just not submit the form and go some where else?

Stephen, there is no type=“cancel” in the specs… but why does Jim Thatcher mention it?? Is it a mistake?

That is a mistake. There are a number of new input types being introduced in HTML 5 and even HTML 5 does not have type=cancel. There is no such thing as type=cancel in any version of HTML. There is no need for it either since the easiest way to cancel a form is to just not press the submit button.

Just to make things easier here’s the complete list

type=color (HTML 5 only)
type=date (HTML 5 only)
type=datetime (HTML 5 only)
type=datetime-local (HTML 5 only)
type=emaiil (HTML 5 only)
type=month (HTML 5 only)
type=number (HTML 5 only)
type=range (HTML 5 only)
type=search (HTML 5 only)
type=tel (HTML 5 only)
type=tiime (HTML 5 only)
type=url (HTML 5 only)
type=week (HTML 5 only)

The nearest to a ‘cancel’, would be the ‘cancelable’ value appears within XForms but that’s beyond the scope of HTML. I suspect Jim was thinking of common text rather than “type” and got muddled.

there is no cancel input type. you have to use submit instead of cancel and write onclick javascript function to redirect the page.

I think this will help. if not sorry…

all the best