Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions

Cancel button


Reply

6 Posts   1036 Views

Avatar
jennymgray

17 November 2011 at 10:16pm Community Member, 9 Posts

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

Avatar
Willr

17 November 2011 at 11:28pm Forum Moderator, 5511 Posts

Instead of the plain FormAction class you'll want to add an action of class ResetFormAction for a reset button.

Avatar
jennymgray

18 November 2011 at 12:02am Community Member, 9 Posts

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.

Avatar
SheaDawson

3 April 2012 at 5:39pm Community Member, 46 Posts

Did you manage to find a solution for this?

Thanks :)

Avatar
jennymgray

3 April 2012 at 7:58pm Community Member, 9 Posts

No, I didn't. I couldn't get round the validation problem so I gave up.

Avatar
Willr

5 April 2012 at 10:58pm Forum Moderator, 5511 Posts

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.