[prog] PHP and cancel buttons

Rachel McConnell rachel at xtreme.com
Tue Jun 29 18:18:52 EST 2004


dave wrote:
> 
> If you don't want to start a new form, you can use:
> 	<input type="button" value="Cancel" onClick="history.back()">
> 

There are a couple of things to remember about using code like this:

* any use of an event handler such as onClick will fail if the user 
doesn't have javascript turned on in their browser.

* the "history.back()" bit specifically will not behave as expected if 
the user has done anything Odd before getting to the form page, or 
reaches it by an email link or by typing it into the URL bar directly. 
For example, if the form in question has validation and the user is on 
it the second time around ("You must fill in all fields to go on"), 
history.back() will get them to the original form page without the 
validation messages.  If they've navigated to, say, Google, and then 
gone back to the form page, they'll get Google again.

Consider the following code:

<form action="{URL of the page you want to cancel TO}">
	<input type="submit" value="Cancel"/>
</form>

This is more wordy, and will require a surrounding table if the Cancel 
and Submit buttons need to be side-by-side, but it doesn't have either 
of the above drawbacks.

Rachel



More information about the Programming mailing list