You are here

function hook_privatemsg_message_validate in Privatemsg 6

Same name and namespace in other branches
  1. 6.2 privatemsg.api.php \hook_privatemsg_message_validate()
  2. 7.2 privatemsg.api.php \hook_privatemsg_message_validate()
  3. 7 privatemsg.api.php \hook_privatemsg_message_validate()

Validate a message before it is sent/saved in the database.

Validation errors can be returned, either as a string or as array when there are multiple errors. If the $form flag is set, errors should be reported with form_set_error instead.

@todo adapt api return value changes

Parameters

$message: Message array

Related topics

1 invocation of hook_privatemsg_message_validate()
_privatemsg_validate_message in ./privatemsg.module

File

./privatemsg.api.php, line 304
Privatemsg API Documentation

Code

function hook_privatemsg_message_validate($message, $form = FALSE) {
  global $_privatemsg_invalid_recipients;
  $_privatemsg_invalid_recipients = array();
  $errors = array();
  foreach ($message['recipients'] as $recipient) {
    if ($recipient->name == 'blocked user') {
      $_privatemsg_invalid_recipients[] = $recipient->uid;
      $errors[] = t('%name has chosen to not recieve any more messages from you.', array(
        '%name' => $recipient->name,
      ));
    }
  }
}