1778 Posts in 581 Topics by 555 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 511 Views |
-
Cancel button

17 November 2011 at 10:16pm
Hi,
I'd like to put a cancel button on a form rather than rely on people using the back button. I've added a FormAction and coded the function so it just does redirectBack().
My problem is that my form's validation is kicking in before the cancel function code is fired. Because the form has required fields, the validation fails, and instead of returning where they came from, the form is displayed again with errors highlighted.
I've checked the contents of $data in my validator class, but it doesn't have anything which indicates the button pressed, so I can't return without validating.
How can I add my cancel button? Is there some other FormAction that I've overlooked, or some other way of not running the validation?
Thanks
-
Re: Cancel button

17 November 2011 at 11:28pm
Instead of the plain FormAction class you'll want to add an action of class ResetFormAction for a reset button.
-
Re: Cancel button

18 November 2011 at 12:02am
Thank you, but that's not quite what I'm after. The ResetFormAction creates an <input type = "reset" which resets the form field contents to their original values.
I'd like my cancel button to redirect users away from the form page, but with FormAction the validation keeps getting in the way of any redirect code I write.
-
Re: Cancel button

3 April 2012 at 7:58pm
No, I didn't. I couldn't get round the validation problem so I gave up.
-
Re: Cancel button

5 April 2012 at 10:58pm
The key is not to make it a button. Make a literal field that contains a plain link.
Heres an example CancelFormAction class I knocked up - https://gist.github.com/2309951.
| 511 Views | ||
|
Page:
1
|
Go to Top |



