comment_form_validate($form, &$form_state)Validate comment form submissions.
modules/comment/comment.module, line 1978
<?php
function comment_form_validate($form, &$form_state) {
global $user;
$comment = (object) $form_state['values'];
field_attach_form_validate('comment', $comment, $form, $form_state);
if (!empty($form_state['values']['cid'])) {
if ($form_state['values']['date'] && strtotime($form_state['values']['date']) === FALSE) {
form_set_error('date', t('You have to specify a valid date.'));
}
if ($form_state['values']['name'] && !$account = user_load_by_name($form_state['values']['name'])) {
form_set_error('name', t('You have to specify a valid author.'));
}
}
// Check validity of name, mail and homepage (if given).
if (!$user->uid || $form_state['values']['is_anonymous']) {
$node = node_load($form_state['values']['nid']);
if (variable_get('comment_anonymous_' . $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) > COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
if ($form_state['values']['name']) {
$query = db_select('users', 'u');
$query->addField('u', 'uid', 'uid');
$taken = $query
->condition('name', db_like($form_state['values']['name']), 'LIKE')
->countQuery()
->execute()
->fetchField();
if ($taken != 0) {
form_set_error('name', t('The name you used belongs to a registered user.'));
}
}
elseif (variable_get('comment_anonymous_' . $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) == COMMENT_ANONYMOUS_MUST_CONTACT) {
form_set_error('name', t('You have to leave your name.'));
}
if ($form_state['values']['mail']) {
if (!valid_email_address($form_state['values']['mail'])) {
form_set_error('mail', t('The e-mail address you specified is not valid.'));
}
}
elseif (variable_get('comment_anonymous_' . $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) == COMMENT_ANONYMOUS_MUST_CONTACT) {
form_set_error('mail', t('You have to leave an e-mail address.'));
}
if ($form_state['values']['homepage']) {
if (!valid_url($form_state['values']['homepage'], TRUE)) {
form_set_error('homepage', t('The URL of your homepage is not valid. Remember that it must be fully qualified, i.e. of the form <code>http://example.com/directory</code>.'));
}
}
}
}
}
?>