function privatemsg_new_validate in Privatemsg 6.2
Same name and namespace in other branches
- 7.2 privatemsg.pages.inc \privatemsg_new_validate()
- 7 privatemsg.pages.inc \privatemsg_new_validate()
1 call to privatemsg_new_validate()
- privatemsg_forward_form_submit in privatemsg_forward/
privatemsg_forward.module - Submit function for forward form.
1 string reference to 'privatemsg_new_validate'
- _privatemsg_form_base_fields in ./
privatemsg.pages.inc - Returns the common fields of the reply and new form.
File
- ./
privatemsg.pages.inc, line 484 - User menu callbacks for Privatemsg.
Code
function privatemsg_new_validate($form, &$form_state) {
// The actual message that is being sent, we create this during validation and pass to submit to send out.
$message = $form_state['values'];
$message['timestamp'] = time();
// Avoid subjects which only consist of a space as these can not be clicked.
$message['subject'] = trim($message['subject']);
$trimed_body = trim(truncate_utf8(strip_tags($message['body']), 50, TRUE, TRUE));
if (empty($message['subject']) && !empty($trimed_body)) {
$message['subject'] = $trimed_body;
}
// Only parse the user string for a new thread.
if (!isset($message['thread_id'])) {
list($message['recipients'], $invalid, $duplicates, $denieds) = _privatemsg_parse_userstring($message['recipient']);
}
else {
// Load participants. Limit recipients to visible unless read_all is TRUE.
$message['recipients'] = _privatemsg_load_thread_participants($message['thread_id'], $message['read_all'] ? FALSE : $message['author']);
}
if (!empty($invalid)) {
// Display information about invalid recipients.
drupal_set_message(t('The following recipients will not receive this private message: @invalid.', array(
'@invalid' => implode(", ", $invalid),
)), 'error');
}
if (!empty($denieds)) {
// Display information about denied recipients.
drupal_set_message(t('You do not have access to write these recipients: @denieds.', array(
'@denieds' => implode(", ", $denieds),
)), 'error');
}
if (!empty($duplicates)) {
// Add JS and CSS to allow choosing the recipient.
drupal_add_js(drupal_get_path('module', 'privatemsg') . '/privatemsg-alternatives.js');
// Display information about recipients that couldn't be identified
// uniquely.
$js_duplicates = array();
foreach ($duplicates as $string => $duplicate) {
$alternatives = array();
foreach ($duplicate as $match) {
$formatted_match = privatemsg_recipient_format($match, array(
'plain' => TRUE,
'unique' => TRUE,
));
$js_duplicates[$formatted_match] = $string;
$alternatives[] = '<span class="privatemsg-recipient-alternative">' . $formatted_match . '</span>';
}
// Build a formatted list of possible recipients.
$alternatives = theme('item_list', $alternatives, NULL, 'ul', array(
'class' => 'action-links',
));
form_set_error('recipient', '<div class="privatemsg-alternative-description">' . t('The site has multiple recipients named %string. Please choose your intended recipient: !list', array(
'%string' => $string,
'!list' => $alternatives,
)) . '</div>');
}
// Also make that information available to the javascript replacement code.
drupal_add_js(array(
'privatemsg_duplicates' => $js_duplicates,
), 'setting');
}
$validated = _privatemsg_validate_message($message, TRUE);
foreach ($validated['messages'] as $type => $text) {
drupal_set_message($text, $type);
}
$form_state['validate_built_message'] = $message;
}