function print_mail_form_validate in Printer, email and PDF versions 5.4
Same name and namespace in other branches
- 5.3 print_mail/print_mail.inc \print_mail_form_validate()
- 6 print_mail/print_mail.inc \print_mail_form_validate()
- 7.2 print_mail/print_mail.inc \print_mail_form_validate()
- 7 print_mail/print_mail.inc \print_mail_form_validate()
- 5.x print_mail/print_mail.inc \print_mail_form_validate()
Validate the send by-email form submission.
File
- print_mail/
print_mail.inc, line 185
Code
function print_mail_form_validate($form_id, $form_values, $form) {
if (array_key_exists('cancel', $form['#post'])) {
return;
}
$from_addr = trim($form_values['fld_from_addr']);
$test = user_validate_mail($from_addr);
if ($test) {
form_set_error('fld_from_addr', $test);
}
// All new-lines are replaced by commas
$to_addrs = preg_replace('![\\r|\\n|,]+!', ',', trim($form_values['txt_to_addrs']));
// Create an array from the string
$to_array = explode(',', $to_addrs);
// Verify each element of the array
foreach ($to_array as $key => $address) {
$address = trim($address);
if (preg_match('/(.*?) <(.*)>/s', $address, $matches)) {
// Address is of the type User Name <user@domain.tld>
$test = user_validate_mail($matches[2]);
$to_array[$key] = trim($matches[1]) . ' <' . $matches[2] . '>';
}
else {
// Address must be user@domain.tld
$test = user_validate_mail($address);
}
if ($test) {
form_set_error('txt_to_addrs', $test);
}
}
$print_mail_hourly_threshold = variable_get('print_mail_hourly_threshold', PRINT_MAIL_HOURLY_THRESHOLD);
if (!user_access('administer print') && !flood_is_allowed('print_mail', $print_mail_hourly_threshold - count($to_array) + 1)) {
form_set_error('txt_to_addrs', t('You cannot send more than %number messages per hour. Please reduce the number of recipients.', array(
'%number' => $print_mail_hourly_threshold,
)));
}
// In all fields, prevent insertion of custom headers
foreach ($form_values as $key => $string) {
if (substr($key, 0, 4) == 'fld_' && (strpos($string, "\n") !== FALSE || strpos($string, "\r") !== FALSE)) {
form_set_error($key, 'Found invalid character');
}
}
form_set_value($form['fld_from_addr'], $from_addr);
form_set_value($form['fld_from_name'], trim($form_values['fld_from_name']));
// Re-create the string from the re-organized array
form_set_value($form['txt_to_addrs'], implode(', ', $to_array));
}