empty message
| Project: | Privatemsg |
| Version: | 7.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
i'm posting this as a bug report, but it might be a feature request, i'm not really sure...
in the current build of pm it seems that it is possible to send an empty message. i found this when i inadvertently clicked on 'send message' before i typed anything. to my surprise, it actually sent a message which was blank. would it be possible to add a check to see if a message has been written?
and then one implication of this which i'm not sure how to deal with would be that if the privatemsg system checks to see if a message has been written when the user hits 'send message', how will the 'remove myself from the thread' button work with the pm_forward sub-module? the functionality of that is such that a user can remove themselves without writing a response simply by forwarding the thread without anyone in the 'to' field but with the button clicked to remove themselves. this functionality is great, but if the pm system checks to make sure a message has been written, it would result in an error, correct? any way around this?

#1
This is more or less much be design, atleast for the new message form. You can *either* send a message with an empty subject (subject will be set to first 50 characters of body then) or an empty body but not both.
However, as the reply form does have the subject pre-set, it does not make much sense to send a reply with empty body. Of course, if we change that behavior, the privatemsg_forward module needs to be updated.
I'm changing this to a feature request, because it's not actually a bug imho.
#2
The attached patch blocks empty replies in the API and the form without breaking privatemsg_forward (Untested, though...).
It does that by simply validating this in _privatemsg_validate_message(). The downside is that the message textarea is not marked as an required field but FAPI doesn't allow us to do so. Alternatively, we could set required to TRUE and let privatemsg_forward remove it again.
#3
Do we also want a required check on the form? Something like?
<?php$form['privatemsg']['body'] = array(
...
// Make body required for replies.
'#required' => empty($thread_id) ? FALSE : TRUE,
);
?>
?
#4
@nbz
The issue is we can't have the required optional then. For example, #548188: add/remove somebody to/from some discussion integrates itself into the reply form and relies on the fact that you can submit that form without writing something into that field. If something has been written, it does add a reply and if not, it just forwards the thread.
However, we need to update http://blog.worldempire.ch/api/function/privatemsg_reply then and make $body a required param.
#5
Made the $body param to privatemsg_reply() required...
#6
Added some tests for this and also extended the existing tests for the write/reply form. It does probably not test everything but it's a start that we can extend if there are bugs reported with a special use case.
#7
Added to 6.x-1.x-dev and 7.x-1.x-dev.
#8
Automatically closed -- issue fixed for 2 weeks with no activity.