Drupal: cancel button on edit node page

Are you missing a Cancel Button in your Drupal installation? Great. I know the feeling. But as they say: there’s a module for that. For many Drupal related tasks there is already a module available at drupal.org. But some essential tasks can be so ‘small’ that the related module would be even smaller – documenting and uploading it seems to be almost a waste of time. And since writing your own module in Drupal is actually not that difficult, finding a solution for such ‘small tasks’ can be as easy as copy-paste-save-upload. And this also applies to the missing cancel button.

When I needed a cancel button for one project I was working on, I ran into exactly this situation. Or maybe ‘situation’ is to big a word for this – anyways. I needed to add a cancel button to the “new node” and “edit node” screens for all pages. You may think Why not just leave the page instead of clicking a cancel button? And I must agree: from a functional perspective such a button would be redundant.  But from a UX perspective it may very well make sense to have that button: I actually only needed that extra button because the client I worked for was used to having a cancel button from his previous CMS. He was a bit irritated that there was no cancel button in the drupal installation I developed for him. Also telling him “Just leave the page” did not help.

Instead a quick search helped. I found this little snippet from Pascal Duez that does just that: adding a custom cancel button to the “new node” and “edit node” screen of all pages. That was exactly what I was looking for. You can find the module on gihub right here: gist.github.com/pascalduez/1888373

This is what the “new node” and “edit node” screen looks like when the module is activated:

Drupal Cancel Button Example Screenshot

custom cancel-button for Drupal

There is also a slightly more complex, or actually more ‘handy’ version of that script. It also forwards the user to a different, useful page, according to the context in which the cancel button was clicked:

” If the “Cancel” button is clicked, the user is being redirected the following way:

  1. If a “destination” paramter is set, this is used
  2. If no destination parameter is set and we’re in an edit form, the user is being redirected to the node display
  3. Otherwise the user is being redirected to the frontpage “

You can find the slightly more complex module from here:
julian.pustkuchen.com/en/drupal-7-snippet-add-cancel-button-content-edit-create-forms

Leave a Reply

Your email address will not be published. Required fields are marked *