Hi,

when i write a new message and click on cancel, i got the error: "There are no valid recipients." and Subject etc.
When i click on cancel i don't care that there are no infos. I thought the button should delete the message.

Thank you

strauch

Comments

naheemsays’s picture

Title: Abort Button at a new message malfunction » Cancel Button does not work

Yeah, just tested.

Go to messages/new and without entering any info, just click cancel.

You will get an error message:

* To field is required.
* Subject field is required.
* There are no valid recipients.

berdir’s picture

What should the cancel button do ? Just empty the form or going back to the previous site ?

naheemsays’s picture

It should go to the messages page. I had a look around core and nowhere similar (create content etc) has a cancel button. maybe just remove it?

strauch’s picture

i don't need the button, if i don't want to write the message i close the window or click on another menu link or something else. It is propably possible that someone press the wrong button and the text is gone, so i would remove the button.

berdir’s picture

Status: Active » Needs review
StatusFileSize
new1.07 KB

Maybe adding a simple Cancel-Link similar to the "Do you really want to delete that"-form that core uses.

Here is a simple patch that does change this.

B00N’s picture

Version: » 6.x-1.0-rc2
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new936 bytes

I've tested the patch (an 6.x-1.0-rc2) and it works.

it would be nice to have a #id to style with CSS. So i changed the following line in the patch from post #5:

'#value' => l(t('Cancel'), 'messages'),

to

'#value' => l(t('Cancel'), 'messages', array('attributes' => array('id' => 'edit-cancel'))),

Can you use this patch for the next release?

tstoeckler’s picture

To my mind, it doesn't really make sense to confirm deletion, because you haven't saved anything before, you have just entered some stuff and are leaving the page, without ever having touched the db. And similar things are nowhere to be found in Drupal core. Visit node/add/story, enter something and click on any menu item. No deletion there, so why add it here?
The only logical thing IMO is to delete the cancel button altogether, it has no functionality as of now and it is not needed for anything -> kill it!

berdir’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.31 KB

There is a similiar issue open for Drupal core, http://drupal.org/node/116939.

I think adding a Cancel link would be a good idea, both Facebook ( grey "Cancel" button) and Gmail ("Discard" button) are also having something similiar.

Think about users who are not familar with browsers, there are many users who don't know/use the browser back button and a cancel link does not take up much space.

Attached is a updated patch which does use $_REQUEST['destination'] if set.

tstoeckler’s picture

I still don't understand it what case this is actually needed, but well, I guess it's nothing critical as long as the button is fixed.

quicksketch’s picture

Status: Needs review » Reviewed & tested by the community

This looks great to me too. I agree the "Cancel" link/button is good to include. I'm glad to see we're using a link rather than a button to fit with Drupal convention.

litwol’s picture

Status: Reviewed & tested by the community » Fixed

Commited! thanks alot.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

I know that this issue is closed but for the sake of others looking I simply used drupal_get_messages('error'); drupal_goto('somewhere/else'); for the action of the $form_state['clicked_button']['#value'] == 'Cancel'. The drupal_get_messages('error') will clear the validation error message queue. Both the drupal_get_messages('error') and the drupal_goto('somewhere/else') calls need to be in the _validate callback.

function mymodule_form_validate($form, &$form_state) {
  if ($form_state['clicked_button']['#value'] == 'Cancel') {
    drupal_get_messages('error');
    drupal_goto('node');
  }
  ... ...
}
litwol’s picture

The above solution is kind of bad (sorry!), i advise not using it.

Anonymous’s picture

@litwol: Do you have a better solution? Saying it is bad without offering advice of something better is like throwing stones at the leper instead of trying to offer him a healing salve. I did research how others have resolved this and all I found was a link were suggestions to use a link instead of a form button.

litwol’s picture

What is wrong with a link? If you want to make it look like a button then all you have to do is style the link look like a button. Perhaps place an image there or something.

Anonymous’s picture

There is nothing wrong with a link styled as you suggest if you know what the default button looks like for every browser that is possible to be used. You still don't give a reason as to what is wrong with what I suggested; why is it such a poor method? Sure, the verification code still executes and the errors are being cleared; but, it does give the desired result. I do find it a fault of Drupal to not provide a way to skip the validation for a '#type' => 'button' or to even provide a '#type' => 'cancel' that defaults to skipping the validation.